Skip to content

fix(sorts): add testmod() call to gnome_sort __main__ block - #15146

Open
Ankur-Kataria wants to merge 2 commits into
TheAlgorithms:masterfrom
Ankur-Kataria:fix/issue-14881
Open

fix(sorts): add testmod() call to gnome_sort __main__ block#15146
Ankur-Kataria wants to merge 2 commits into
TheAlgorithms:masterfrom
Ankur-Kataria:fix/issue-14881

Conversation

@Ankur-Kataria

Copy link
Copy Markdown
Contributor

Describe your change:

sorts/gnome_sort.py was not calling testmod() in its __main__ block, so running the file directly with python3 gnome_sort.py silently skipped doctest verification. Every other sort in this directory that has doctests (e.g. insertion_sort.py, shell_sort.py, comb_sort.py) already calls testmod() before prompting for user input.

This PR adds the two-line pattern used across the rest of the directory:

from doctest import testmod
testmod()

Fixes #14881

  • Fix a bug or typo in an existing algorithm?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

Fixes TheAlgorithms#14881 - gnome_sort.py did not call testmod() in its __main__
block, unlike other sort implementations (insertion_sort, shell_sort,
etc.). Running the file directly with python3 gnome_sort.py would
skip doctest verification. Now consistent with the rest of the sorts/
directory.
@algorithms-keeper algorithms-keeper Bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Sep 1, 2026
Comment thread sorts/gnome_sort.py

testmod()

user_input = input("Enter numbers separated by a comma:\n").strip()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will crash in doctests as discussed in CONTRIBUTING.md

Comment thread .oss-upstream
@@ -0,0 +1 @@
TheAlgorithms/Python

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is not needed or welcome.

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

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gnome_sort.py main block missing doctest.testmod() call

2 participants