-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_recursion.py
92 lines (71 loc) · 2.04 KB
/
test_recursion.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import recursion
def test_traverse_array(capfd):
"""
Test def traverse_array(list1) which is in recursion.py
"""
array = [ 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, 29]
], 30, 31
], 32
], 33
]
result = "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 29 30 31 32 33 "
recursion.traverse_array(array)
out, err = capfd.readouterr()
assert out == result
def test_ch11_exercise1():
test1 = ["ab", "c", "def", "ghij"]
result1 = 10
test2 = ["abc", "xyz"]
result2 = 6
test3 = ["asdf", "asdf", "poi"]
result3 = 11
assert recursion.ch11_exercise1(test1) == result1
assert recursion.ch11_exercise1(test2) == result2
assert recursion.ch11_exercise1(test3) == result3
def test_ch11_exercise2():
test1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
result1 = [2, 4, 6, 8, 10]
test2 = [8, 8]
result2 = [8, 8]
test3 = [5]
result3 = []
test4 = [1, 3, 5, 8, 10, 11, 15, 16, 17]
result4 = [8, 10, 16]
assert recursion.ch11_exercise2(test1) == result1
assert recursion.ch11_exercise2(test2) == result2
assert recursion.ch11_exercise2(test3) == result3
def test_ch11_exercise3():
test1 = 7
result1 = 28
test2 = 8
result2 = 36
test3 = 9
result3 = 45
assert recursion.ch11_exercise3(test1) == result1
assert recursion.ch11_exercise3(test2) == result2
assert recursion.ch11_exercise3(test3) == result3
def test_ch11_exercise4():
test1 = "abcdefghijklmnopqrstuvwxyz"
result1 = 23
test2 = "x"
result2 = 0
test3 = "aax"
result3 = 2
test4 = "abcdxefg"
result4 = 4
assert recursion.ch11_exercise4(test1) == result1
assert recursion.ch11_exercise4(test2) == result2
assert recursion.ch11_exercise4(test3) == result3