forked from rriehle/Python300-2017q3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_generator.py
77 lines (54 loc) · 1.24 KB
/
test_generator.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
"""
test_generator.py
tests the solution to the generator lab
can be run with py.test or nosetests
"""
import generator_solution as gen
def test_intsum():
g = gen.intsum()
assert next(g) == 0
assert next(g) == 1
assert next(g) == 3
assert next(g) == 6
assert next(g) == 10
assert next(g) == 15
def test_intsum2():
g = gen.intsum2()
assert next(g) == 0
assert next(g) == 1
assert next(g) == 3
assert next(g) == 6
assert next(g) == 10
assert next(g) == 15
def test_doubler():
g = gen.doubler()
assert next(g) == 1
assert next(g) == 2
assert next(g) == 4
assert next(g) == 8
assert next(g) == 16
assert next(g) == 32
for i in range(10):
j = next(g)
assert j == 2**15
def test_fib():
g = gen.fib()
assert next(g) == 1
assert next(g) == 1
assert next(g) == 2
assert next(g) == 3
assert next(g) == 5
assert next(g) == 8
assert next(g) == 13
assert next(g) == 21
def test_prime():
g = gen.prime()
assert next(g) == 2
assert next(g) == 3
assert next(g) == 5
assert next(g) == 7
assert next(g) == 11
assert next(g) == 13
assert next(g) == 17
assert next(g) == 19
assert next(g) == 23