|
13 | 13 | from multiprocessing import Lock, Pipe, Process
|
14 | 14 |
|
15 | 15 | # lock used to ensure that two processes do not access a pipe at the same time
|
16 |
| -process_lock = Lock() |
| 16 | +# NOTE This breaks testing on build runner. May work better locally |
| 17 | +# process_lock = Lock() |
17 | 18 |
|
18 | 19 | """
|
19 | 20 | The function run by the processes that sorts the list
|
|
28 | 29 |
|
29 | 30 |
|
30 | 31 | def oe_process(position, value, l_send, r_send, lr_cv, rr_cv, result_pipe):
|
31 |
| - global process_lock |
| 32 | + process_lock = Lock() |
32 | 33 |
|
33 | 34 | # we perform n swaps since after n swaps we know we are sorted
|
34 | 35 | # we *could* stop early if we are sorted already, but it takes as long to
|
@@ -72,6 +73,26 @@ def oe_process(position, value, l_send, r_send, lr_cv, rr_cv, result_pipe):
|
72 | 73 |
|
73 | 74 |
|
74 | 75 | def odd_even_transposition(arr):
|
| 76 | + """ |
| 77 | + >>> odd_even_transposition(list(range(10)[::-1])) == sorted(list(range(10)[::-1])) |
| 78 | + True |
| 79 | + >>> odd_even_transposition(["a", "x", "c"]) == sorted(["x", "a", "c"]) |
| 80 | + True |
| 81 | + >>> odd_even_transposition([1.9, 42.0, 2.8]) == sorted([1.9, 42.0, 2.8]) |
| 82 | + True |
| 83 | + >>> odd_even_transposition([False, True, False]) == sorted([False, False, True]) |
| 84 | + True |
| 85 | + >>> odd_even_transposition([1, 32.0, 9]) == sorted([False, False, True]) |
| 86 | + False |
| 87 | + >>> odd_even_transposition([1, 32.0, 9]) == sorted([1.0, 32, 9.0]) |
| 88 | + True |
| 89 | + >>> unsorted_list = [-442, -98, -554, 266, -491, 985, -53, -529, 82, -429] |
| 90 | + >>> odd_even_transposition(unsorted_list) == sorted(unsorted_list) |
| 91 | + True |
| 92 | + >>> unsorted_list = [-442, -98, -554, 266, -491, 985, -53, -529, 82, -429] |
| 93 | + >>> odd_even_transposition(unsorted_list) == sorted(unsorted_list + [1]) |
| 94 | + False |
| 95 | + """ |
75 | 96 | process_array_ = []
|
76 | 97 | result_pipe = []
|
77 | 98 | # initialize the list of pipes where the values will be retrieved
|
|
0 commit comments