forked from hedyorg/hedy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_level_15.py
71 lines (63 loc) · 1.64 KB
/
test_level_15.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
import hedy
import textwrap
from test_level_01 import HedyTester
class TestsLevel15(HedyTester):
level = 15
def test_while_equals(self):
code = textwrap.dedent("""\
antwoord is 0
while antwoord != 25
antwoord is ask 'Wat is 5 keer 5?'
print 'Goed gedaan!'""")
expected = textwrap.dedent("""\
antwoord = 0
while str(antwoord).zfill(100)!=str(25).zfill(100):
antwoord = input(f'Wat is 5 keer 5?')
try:
antwoord = int(antwoord)
except ValueError:
try:
antwoord = float(antwoord)
except ValueError:
pass
time.sleep(0.1)
print(f'Goed gedaan!')""")
self.multi_level_tester(
code=code,
max_level=16,
expected=expected,
expected_commands=['is', 'while', 'ask', 'print']
)
def test_while_undefined_var(self):
code = textwrap.dedent("""\
while antwoord != 25
print 'hoera'""")
self.multi_level_tester(
code=code,
exception=hedy.exceptions.UndefinedVarException,
max_level=16,
)
def test_while_smaller(self):
code = textwrap.dedent("""\
getal is 0
while getal < 100000
getal is ask 'HOGER!!!!!'
print 'Hoog he?'""")
expected = textwrap.dedent("""\
getal = 0
while str(getal).zfill(100)<str(100000).zfill(100):
getal = input(f'HOGER!!!!!')
try:
getal = int(getal)
except ValueError:
try:
getal = float(getal)
except ValueError:
pass
time.sleep(0.1)
print(f'Hoog he?')""")
self.multi_level_tester(
code=code,
max_level=16,
expected=expected
)