-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_loop_stack.py
147 lines (121 loc) · 3.59 KB
/
test_loop_stack.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import pytest
from loop_stack import LoopStack
from loop_tree import LoopTree
def test_loop_stack_leaf():
stack = LoopStack([
LoopTree.LEAF(9),
])
stack.start_loop()
for _ in range(9):
assert not stack.next()
assert stack.next()
with pytest.raises(ValueError) as ex:
stack.next()
assert 'No current loop' == str(ex.value)
def test_loop_stack_nested():
stack = LoopStack([
LoopTree.CARTESIAN(3, [
LoopTree.LEAF(2),
LoopTree.LEAF(4),
]),
])
stack.start_loop()
for j in range(3):
assert not stack.next()
stack.start_loop()
for i in range(2):
assert not stack.next()
assert stack.next()
stack.start_loop()
for i in range(4):
assert not stack.next()
assert stack.next()
assert stack.next()
with pytest.raises(ValueError) as ex:
stack.next()
assert 'No current loop' == str(ex.value)
def test_loop_stack_nested2():
stack = LoopStack([
LoopTree.CARTESIAN(2, [
LoopTree.ROLLED_OUT([
[LoopTree.LEAF(3), LoopTree.LEAF(1)],
[LoopTree.LEAF(4), LoopTree.LEAF(2)],
]),
]),
])
stack.start_loop()
for _ in range(2):
assert not stack.next()
stack.start_loop()
for loop1, loop2 in [(3, 1), (4, 2)]:
assert not stack.next()
stack.start_loop()
for _ in range(loop1):
assert not stack.next()
assert stack.next()
stack.start_loop()
for _ in range(loop2):
assert not stack.next()
assert stack.next()
assert stack.next()
assert stack.next()
with pytest.raises(ValueError) as ex:
stack.next()
assert 'No current loop' == str(ex.value)
def test_loop_stack_complex_no_break():
stack = LoopStack([
LoopTree.CARTESIAN(4, [
LoopTree.LEAF(9),
LoopTree.ROLLED_OUT([
[LoopTree.LEAF(8), LoopTree.LEAF(1)],
[LoopTree.LEAF(0), LoopTree.LEAF(5)],
[LoopTree.LEAF(7), LoopTree.LEAF(2)],
]),
LoopTree.CARTESIAN(6, [
LoopTree.LEAF(3),
]),
]),
LoopTree.ROLLED_OUT([
[LoopTree.LEAF(10)],
[LoopTree.LEAF(2)],
]),
])
stack.start_loop()
for _ in range(4):
assert not stack.next()
stack.start_loop()
for _ in range(9):
assert not stack.next()
assert stack.next()
stack.start_loop()
for loop1, loop2 in [(8, 1), (0, 5), (7, 2)]:
assert not stack.next()
stack.start_loop()
for _ in range(loop1):
assert not stack.next()
assert stack.next()
stack.start_loop()
for _ in range(loop2):
assert not stack.next()
assert stack.next()
assert stack.next()
stack.start_loop()
for _ in range(6):
assert not stack.next()
stack.start_loop()
for _ in range(3):
assert not stack.next()
assert stack.next()
assert stack.next()
assert stack.next()
stack.start_loop()
for loop in [10, 2]:
assert not stack.next()
stack.start_loop()
for _ in range(loop):
assert not stack.next()
assert stack.next()
assert stack.next()
with pytest.raises(ValueError) as ex:
stack.next()
assert 'No current loop' == str(ex.value)