-
Notifications
You must be signed in to change notification settings - Fork 0
/
do_terminated_lists_overlap.py
47 lines (37 loc) · 1.14 KB
/
do_terminated_lists_overlap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import functools
from test_framework import generic_test
from test_framework.test_failure import TestFailure
from test_framework.test_utils import enable_executor_hook
def overlapping_no_cycle_lists(L0, L1):
a = L0
b = L1
while a is not b:
a = a.next if a else L1
b = b.next if b else L0
return a
@enable_executor_hook
def overlapping_no_cycle_lists_wrapper(executor, L0, L1, common):
if common:
if L0:
i = L0
while i.next:
i = i.next
i.next = common
else:
L0 = common
if L1:
i = L1
while i.next:
i = i.next
i.next = common
else:
L1 = common
result = executor.run(
functools.partial(overlapping_no_cycle_lists, L0, L1))
if result != common:
raise TestFailure('Invalid result')
if __name__ == '__main__':
exit(
generic_test.generic_test_main("do_terminated_lists_overlap.py",
'do_terminated_lists_overlap.tsv',
overlapping_no_cycle_lists_wrapper))