Skip to content

Tests for odd_even_transposition_parallel #10926

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

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions sorts/odd_even_transposition_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,34 @@ def oe_process(position, value, l_send, r_send, lr_cv, rr_cv, result_pipe):


def odd_even_transposition(arr):
"""
>>> 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'

"""
process_array_ = []
result_pipe = []
# initialize the list of pipes where the values will be retrieved
Expand Down