Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for odd_even_transposition_parallel #10926

Merged

Conversation

RaymondDashWu
Copy link
Contributor

Describe your change:

Contributes to #9943. It should be noted that there is currently a bug in this algo as described in #10925. Will fix in a separate PR after this gets merged.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?
  • Add test cases

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".

@algorithms-keeper algorithms-keeper bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass labels Oct 24, 2023
@cclauss
Copy link
Member

cclauss commented Oct 25, 2023

Your long builds are unique. Did you try running the doctests locally?
python3 -m doctest -v sorts/odd_even_transposition_parallel.py

@cclauss
Copy link
Member

cclauss commented Oct 25, 2023

Or you can comment out your tests and see if builds start to work again.

@cclauss
Copy link
Member

cclauss commented Oct 25, 2023

sorts/merge_insertion_sort.py ....                                       [ 93%]
sorts/merge_sort.py .                                                    [ 93%]
sorts/msd_radix_sort.py ....                                             [ 93%]
sorts/natural_sort.py .                                                  [ 93%]
sorts/odd_even_sort.py .                                                 [ 93%]
Error: The operation was canceled.

@RaymondDashWu
Copy link
Contributor Author

RaymondDashWu commented Oct 25, 2023

This is what happens when I run it locally with python3 -m doctest -v sorts/odd_even_transposition_parallel.py. Likely the reason build is hanging. Interestingly though it runs fine when I cd into sorts and then run python3 -m doctest -v odd_even_transposition_parallel.py

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/spawn.py", line 122, in spawn_main
    exitcode = _main(fd, parent_sentinel)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/spawn.py", line 132, in _main
    self = reduction.pickle.load(from_parent)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'odd_even_transposition_parallel'

Comment on lines 76 to 101
>>> odd_even_transposition(list(range(11)[::-1])) == sorted(list(range(11)[::-1]))
True
>>> odd_even_transposition(["a", "x", "c"]) == sorted(["x", "a", "c"])
True
>>> odd_even_transposition([1.9, 42.0, 2.8]) == sorted([1.9, 42.0, 2.8])
True
>>> odd_even_transposition([False, True, False]) == sorted([False, False, True])
True
>>> odd_even_transposition([1, 32.0, 9]) == sorted([False, False, True])
False
>>> odd_even_transposition([1, 32.0, 9]) == sorted([1.0, 32, 9.0])
True
>>> unsorted_list = [-442, -98, -554, 266, -491, 985, -53, -529, 82, -429]
>>> odd_even_transposition(unsorted_list) == sorted(unsorted_list)
True
>>> unsorted_list = [-442, -98, -554, 266, -491, 985, -53, -529, 82, -429]
>>> odd_even_transposition(unsorted_list) == sorted(unsorted_list + [1])
False
>>> odd_even_transposition([False, "a", 8]) == sorted([False, "a", 8])
Traceback (most recent call last):
...
TypeError: '>' not supported between instances of 'bool' and 'str'
>>> odd_even_transposition([8, "a"]) == sorted(["a", 8])
Traceback (most recent call last):
...
TypeError: '<' not supported between instances of 'str' and 'int'
Copy link
Member

@cclauss cclauss Oct 25, 2023

Choose a reason for hiding this comment

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

Let's comment out the doctests and see if the build passes. Then we can add tests one or two at a time until we find the infinite loop.

Suggested change
>>> odd_even_transposition(list(range(11)[::-1])) == sorted(list(range(11)[::-1]))
True
>>> odd_even_transposition(["a", "x", "c"]) == sorted(["x", "a", "c"])
True
>>> odd_even_transposition([1.9, 42.0, 2.8]) == sorted([1.9, 42.0, 2.8])
True
>>> odd_even_transposition([False, True, False]) == sorted([False, False, True])
True
>>> odd_even_transposition([1, 32.0, 9]) == sorted([False, False, True])
False
>>> odd_even_transposition([1, 32.0, 9]) == sorted([1.0, 32, 9.0])
True
>>> unsorted_list = [-442, -98, -554, 266, -491, 985, -53, -529, 82, -429]
>>> odd_even_transposition(unsorted_list) == sorted(unsorted_list)
True
>>> unsorted_list = [-442, -98, -554, 266, -491, 985, -53, -529, 82, -429]
>>> odd_even_transposition(unsorted_list) == sorted(unsorted_list + [1])
False
>>> odd_even_transposition([False, "a", 8]) == sorted([False, "a", 8])
Traceback (most recent call last):
...
TypeError: '>' not supported between instances of 'bool' and 'str'
>>> odd_even_transposition([8, "a"]) == sorted(["a", 8])
Traceback (most recent call last):
...
TypeError: '<' not supported between instances of 'str' and 'int'
# >>> odd_even_transposition(list(range(11)[::-1])) == sorted(list(range(11)[::-1]))
True
# >>> odd_even_transposition(["a", "x", "c"]) == sorted(["x", "a", "c"])
True
# >>> odd_even_transposition([1.9, 42.0, 2.8]) == sorted([1.9, 42.0, 2.8])
True
# >>> odd_even_transposition([False, True, False]) == sorted([False, False, True])
True
# >>> odd_even_transposition([1, 32.0, 9]) == sorted([False, False, True])
False
# >>> odd_even_transposition([1, 32.0, 9]) == sorted([1.0, 32, 9.0])
True
>>> unsorted_list = [-442, -98, -554, 266, -491, 985, -53, -529, 82, -429]
# >>> odd_even_transposition(unsorted_list) == sorted(unsorted_list)
True
>>> unsorted_list = [-442, -98, -554, 266, -491, 985, -53, -529, 82, -429]
# >>> odd_even_transposition(unsorted_list) == sorted(unsorted_list + [1])
False
# >>> odd_even_transposition([False, "a", 8]) == sorted([False, "a", 8])
Traceback (most recent call last):
...
TypeError: '>' not supported between instances of 'bool' and 'str'
# >>> odd_even_transposition([8, "a"]) == sorted(["a", 8])
Traceback (most recent call last):
...
TypeError: '<' not supported between instances of 'str' and 'int'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just finished pushing all the commits to experiment with. As expected, commenting out all the tests allowed the build to pass. I've made one commit for each test, leaving the rest of the tests commented out except that one. The only exception was the last 3, which were expected to throw exceptions as I couldn't even get those to work locally. If they all fail to build I'm not sure how to proceed.

Copy link
Member

Choose a reason for hiding this comment

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

OK. Please uncomment all the tests that work so that they run. Then leave a blank line and then the commented out tests that seem to run forever. I will look at those in my morning. Thanks for your persistence!!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That won't be necessary as each test failed individually! I'm not familiar enough with the way Python does parallelization but I suspect that has something to do with why these tests all fail.

Copy link
Contributor Author

@RaymondDashWu RaymondDashWu Oct 27, 2023

Choose a reason for hiding this comment

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

After a lot of trial and error I finally figured it out! It had to do with the globally defined process lock. The only thing I couldn't figure out was how to test for multiple different data types. It threw out multiple exceptions with each of those tests and I couldn't figure out how to get those working in doctest. I tried adding # doctest: +IGNORE_EXCEPTION_DETAIL as well as playing around with ellipses (...) to no avail.

For example odd_even_transposition([False, "a", 8]) == sorted([False, "a", 8]) output:

Process Process-47:
Process Process-46:
Traceback (most recent call last):
Traceback (most recent call last):
...
TypeError: '<' not supported between instances of 'str' and 'bool'
TypeError: '>' not supported between instances of 'bool' and 'str'

@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Oct 25, 2023
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Oct 26, 2023
@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Oct 27, 2023
@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Oct 27, 2023
@cclauss cclauss merged commit 0eb1825 into TheAlgorithms:master Oct 27, 2023
@RaymondDashWu RaymondDashWu deleted the odd_even_transposition_parallel_tests branch October 27, 2023 20:17
sedatguzelsemme pushed a commit to sedatguzelsemme/Python that referenced this pull request Sep 15, 2024
* [ADD] tests for odd_even_transposition_parallel

* adding another test because build failed 6 hrs

* comment out all tests to see if it fails

* list(range(10)[::-1]) test uncommented

* [a, x, c] test uncommented

* [1.9, 42.0, 2.8] test uncommented

* [False, True, False] test uncommented

* [1, 32.0, 9] test uncommented

* [1, 32.0, 9] test uncommented

* [-442, -98, -554, 266, -491, 985, -53, -529, 82, -429] test uncommented

* test non global lock

* [DEL] Testing multiple data types. Couldn't get doctest to work

* [ADD] Comment on why non global process lock
@isidroas isidroas mentioned this pull request Jan 25, 2025
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants