-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloop_test.py
72 lines (55 loc) · 2.8 KB
/
loop_test.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
from abeinterpreter import AbeInterpreter
def test_bad_loop_condition():
ai = AbeInterpreter()
out = ai.interpret('He ran into the mountains, but only when he had less than 10 fish. This is what happened there:')
assert out == 'Loop condition syntax is incorrect.'
def test_simple_dec_loop():
ai = AbeInterpreter()
out = ai.interpret('He sold 5 sheep. He ran into the mountains, but only when they had more than 1 fish. This is what happened there: They paid for their 1 mistakes. Alas, I digress. And Abraham spoke!')
out = out.rstrip('\n')
assert out == '1'
def test_simple_inc_loop():
ai = AbeInterpreter()
out = ai.interpret('He ran into the mountains, but only when they had less than 10 fish. This is what happened there: He sold 1 sheep. Alas, I digress. And Abraham spoke!')
out = out.rstrip('\n')
assert out == '10'
def test_nested_loop():
ai = AbeInterpreter()
out = ai.interpret('''He sold 2 sheep.
He ran into the mountains, but only when they had more than 0 fish. This is what happened there:
They paid for their 1 mistakes. Overhead, the geese flew 1 miles east. He sold 2 sheep.
He ran into the mountains, but only when they had more than 0 fish. This is what happened there:
They paid for their 1 mistakes. Overhead, the geese flew 1 miles east. He sold 1 sheep. Overhead, the geese flew 1 miles west.
Alas, I digress.
Overhead, the geese flew 1 miles west.
Alas, I digress.
Overhead, the geese flew 2 miles east.
And Abraham spoke!''')
out = out.strip('\n')
assert out == '4'
def test_fib():
ai = AbeInterpreter()
code = '''
He sold 5 sheep.
Overhead, the geese flew 2 miles east.
He sold 1 sheep.
Overhead, the geese flew 2 miles west.
He ran into the mountains, but only when they had more than 0 fish. This is what happened there:
They paid for their 1 mistakes.
Overhead, the geese flew 2 miles east.
One day he stole his neighbor's goods.
Overhead, the geese flew 1 miles west.
He ran into the mountains, but only when they had more than 0 fish. This is what happened there:
They paid for their 1 mistakes.
Overhead, the geese flew 1 miles east.
He sold 1 sheep.
Overhead, the geese flew 1 miles west.
Alas, I digress.
He repented and returned the property.
Overhead, the geese flew 1 miles west.
Alas, I digress.
Overhead, the geese flew 2 miles east.
And Abraham spoke!
'''
out = ai.interpret(code).strip('\n')
assert out == '8'