-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_helpers.py
More file actions
47 lines (41 loc) · 1.29 KB
/
Copy pathtest_helpers.py
File metadata and controls
47 lines (41 loc) · 1.29 KB
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
# test_helpers.py
def check(expect, actual, message):
"""Check if actual matches expected and print results"""
print(message)
print("EXPECTED:", expect)
print("RETURNED:", actual)
print("PASS" if expect == actual else "FAIL", "\n")
def remove_duplicates_tests(linked_list, expected_values):
"""Test remove_duplicates by comparing to expected_values"""
print("Before: ", end="")
linked_list.print_list()
linked_list.remove_duplicates()
print("After: ", end="")
linked_list.print_list()
result_values = []
node = linked_list.head
while node:
result_values.append(node.value)
node = node.next
if result_values == expected_values:
print("Test PASS\n")
else:
print("Test FAIL\n")
def linkedlist_to_list(head):
"""Convert linked list to Python list"""
result = []
current = head
while current:
result.append(current.value)
current = current.next
return result
def test_partition_list_fn(linked_list_class, check_fn):
"""Test partition list functionality"""
test_cases_passed = 0
ll = linked_list_class(3)
ll.append(1)
ll.append(4)
ll.append(2)
ll.append(5)
ll.partition_list(3)
check_fn([1, 2, 3, 4, 5], linkedlist_to_list(ll.head), "Partition list test")