forked from hedyorg/hedy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_level_13.py
92 lines (79 loc) · 2.17 KB
/
test_level_13.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
import hedy
import textwrap
from test_level_01 import HedyTester
class TestsLevel13(HedyTester):
level = 13
def test_and(self):
code = textwrap.dedent("""\
naam is ask 'hoe heet jij?'
leeftijd is ask 'hoe oud ben jij?'
if naam is 'Felienne' and leeftijd is 37
print 'hallo jij!'""")
expected = textwrap.dedent("""\
naam = input(f'hoe heet jij?')
try:
naam = int(naam)
except ValueError:
try:
naam = float(naam)
except ValueError:
pass
leeftijd = input(f'hoe oud ben jij?')
try:
leeftijd = int(leeftijd)
except ValueError:
try:
leeftijd = float(leeftijd)
except ValueError:
pass
if str(naam) == str('Felienne') and str(leeftijd) == str('37'):
print(f'hallo jij!')""")
self.multi_level_tester(
max_level=16,
code=code,
expected=expected
)
def test_equals(self):
code = textwrap.dedent("""\
name = ask 'what is your name?'
leeftijd = ask 'what is your age?'
if name is 'Hedy' and age is 2
print 'You are the real Hedy!'""")
expected = textwrap.dedent("""\
name = input(f'what is your name?')
try:
name = int(name)
except ValueError:
try:
name = float(name)
except ValueError:
pass
leeftijd = input(f'what is your age?')
try:
leeftijd = int(leeftijd)
except ValueError:
try:
leeftijd = float(leeftijd)
except ValueError:
pass
if str(name) == str('Hedy') and str('age') == str('2'):
print(f'You are the real Hedy!')""")
self.multi_level_tester(
code=code,
max_level=16,
expected=expected,
expected_commands=['ask', 'ask', 'if', 'and', 'print']
)
def test_or(self):
code = textwrap.dedent("""\
if 5 is 5 or 4 is 4
print 'hallo'""")
expected = textwrap.dedent("""\
if str('5') == str('5') or str('4') == str('4'):
print(f'hallo')""")
self.multi_level_tester(
code=code,
max_level=16,
expected=expected,
expected_commands=['if', 'or', 'print']
)