Skip to content

sorts: make pancake_sort generic over Comparable items - #15311

Open
Rokesh2008 wants to merge 2 commits into
TheAlgorithms:masterfrom
Rokesh2008:feat/pancake-sort-comparable
Open

sorts: make pancake_sort generic over Comparable items#15311
Rokesh2008 wants to merge 2 commits into
TheAlgorithms:masterfrom
Rokesh2008:feat/pancake-sort-comparable

Conversation

@Rokesh2008

Copy link
Copy Markdown

Part of #15234

This contribution:

  • switches pancake_sort's type hint from a bare TypeVar to the Comparable/TypeVar-bound pattern used by insertion_sort.py (the reference implementation for this issue)
  • adds doctests covering strings, floats, and randomized int/string collections
  • registers pancake_sort in tests/test_sorts.py's shared SORTS battery (checked against sorted() on the existing case set, including dataclass/NamedTuple items) and in test_sort_rejects_non_comparable_items (confirms TypeError on mixed int/str input)

Tests:

  • python -m doctest -v sorts/pancake_sort.py — 10/10 passed
  • Verified pancake_sort against every case in tests/test_sorts.py's CASES tuple and confirmed it matches sorted(), including Person/Dog comparable objects
  • Confirmed pancake_sort([1, "a"]) raises TypeError

Note: linking with Part of #15234 rather than Fixes/Closes, per the issue's contribution guidance, since other checkboxes on that tracking issue remain open.

Part of TheAlgorithms#15234

- switch pancake_sort's TypeVar to the Comparable/TypeVar-bound
  pattern used by insertion_sort.py
- add doctests covering strings, floats, and random data
- register pancake_sort in tests/test_sorts.py's shared battery and
  the non-comparable-items rejection test
@algorithms-keeper algorithms-keeper Bot added the tests are failing Do not merge until tests pass label Sep 13, 2026
@algorithms-keeper algorithms-keeper Bot removed the tests are failing Do not merge until tests pass label Sep 13, 2026
@cclauss

cclauss commented Sep 13, 2026

Copy link
Copy Markdown
Member

ON HOLD: Our focus is on merging or closing old pull requests before October 1st.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants