Skip to content

Commit

Permalink
removed repeats from level 8 and 9
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraTSD committed Mar 30, 2021
1 parent 64850cd commit 77d0f43
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 224 deletions.
4 changes: 0 additions & 4 deletions grammars/level8.lark
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
start: program
program: _EOL* command (" ")* (_EOL+ command (" ")*)* _EOL* //lines may end on spaces and might be separated by many newlines
?command: print
| repeat
| ifs elses?
| ask
| for_loop
Expand Down Expand Up @@ -40,9 +39,6 @@ list_access_var : var " is " var " at " (index | random)
equality_check: textwithoutspaces " is " textwithoutspaces
in_list_check: textwithoutspaces " in " var

//new for level 5
repeat: "repeat " (NUMBER | var) " times" _EOL (" "+ command) (_EOL " "+ command)*

//new for level 6
?sum: product
| sum " "* "+" " "* product -> addition
Expand Down
4 changes: 0 additions & 4 deletions grammars/level9.lark
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
start: program
program: _EOL* command (" ")* (_EOL+ command (" ")*)* _EOL* //lines may end on spaces and might be separated by many newlines
?command: print
| repeat
| ifs elifs? elses?
| ask
| for_loop
Expand Down Expand Up @@ -41,9 +40,6 @@ list_access_var : var " is " var " at " (index | random)
equality_check: textwithoutspaces " is " textwithoutspaces
in_list_check: textwithoutspaces " in " var

//new for level 5
repeat: "repeat " (NUMBER | var) " times" _EOL (" "+ command) (_EOL " "+ command)*

//new for level 6
?sum: product
| sum " "* "+" " "* product -> addition
Expand Down
4 changes: 2 additions & 2 deletions hedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
5: ['print', 'ask', 'is', 'if', 'repeat'],
6: ['print', 'ask', 'is', 'if', 'repeat'],
7: ['print', 'ask', 'is', 'if', 'repeat'],
8: ['print', 'ask', 'is', 'if', 'repeat', 'for'],
9: ['print', 'ask', 'is', 'if', 'repeat', 'for', 'elif']
8: ['print', 'ask', 'is', 'if', 'for'],
9: ['print', 'ask', 'is', 'if', 'for', 'elif']
}

#
Expand Down
142 changes: 0 additions & 142 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,23 +959,6 @@ def test_if_multiple_lines(self):
print('toetoet')
print('boing boing')""", result)

def test_repeat_with_indent(self):
result = hedy.transpile("""repeat 5 times
print 'koekoek'""", 8)
self.assertEqual("""import random
for i in range(int(5)):
print('koekoek')""",result)

def test_repeat_multiple_lines(self):
result = hedy.transpile("""repeat 5 times
print 'annemaria'
print 'koekoek'""", 8)

self.assertEqual("""import random
for i in range(int(5)):
print('annemaria')
print('koekoek')""", result)

def test_repeat_with_variable_print(self):
result = hedy.transpile("n is 5\nrepeat n times\n print 'me wants a cookie!'", 7)
self.assertEqual(result, """import random
Expand All @@ -1001,18 +984,6 @@ def test_if_nested_in_if(self):
print('mooi')""", result)


#todo: here we have to end in a newline, needs to be fixed!
def test_repeat_nested_in_if(self):
result = hedy.transpile("""kleur is groen
if kleur is groen
repeat 3 times
print 'mooi'""", 8)
self.assertEqual(result, """import random
kleur = 'groen'
if str(kleur) == str('groen'):
for i in range(int(3)):
print('mooi')""")

def test_if_else(self):
result = hedy.transpile("""antwoord is ask Hoeveel is 10 plus 10?
if antwoord is 20
Expand All @@ -1031,15 +1002,6 @@ def test_if_else(self):
print('Foutje')
print('Het antwoord moest zijn '+str(antwoord))""",result)

def test_repeat_basic_print(self):
result = hedy.transpile("""repeat 5 times
print 'me wants a cookie!'""", 8)
self.assertEqual(result, """import random
for i in range(int(5)):
print('me wants a cookie!')""")
self.assertEqual(run_code(result),'me wants a cookie!\nme wants a cookie!\nme wants a cookie!\nme wants a cookie!\nme wants a cookie!')


def test_print_random(self):
result = hedy.transpile("""keuzes is steen, schaar, papier
computerkeuze is keuzes at random
Expand All @@ -1050,34 +1012,6 @@ def test_print_random(self):
print('computer koos '+str(computerkeuze))""", result)


def test_repeat_basic_print_multiple_lines(self):
result = hedy.transpile("""repeat 5 times
print 'cookieeee!'
print 'me wants a cookie!'""", 8)
self.assertEqual("""import random
for i in range(int(5)):
print('cookieeee!')
print('me wants a cookie!')""", result)
# self.assertEqual(run_code(result),'cookieeee!\nme wants a cookie!\ncookieeee!\nme wants a cookie!\ncookieeee!\nme wants a cookie!\ncookieeee!\nme wants a cookie!\ncookieeee!\nme wants a cookie!')

def test_if_repeat_combined_else(self):
result = hedy.transpile("""kleur is ask Wat is je lievelingskleur?
if kleur is groen
repeat 3 times
print 'mooi!'
else
repeat 5 times
print 'niet zo mooi'""", 8)
self.assertEqual("""import random
kleur = input('Wat is je lievelingskleur?')
if str(kleur) == str('groen'):
for i in range(int(3)):
print('mooi!')
else:
for i in range(int(5)):
print('niet zo mooi')""", result)


class TestsLevel9(unittest.TestCase):

def test_for_loop(self):
Expand Down Expand Up @@ -1163,32 +1097,6 @@ def test_if_multiple_lines(self):
print('toetoet')
print('boing boing')""", result)

def test_repeat_with_indent(self):
result = hedy.transpile("""repeat 5 times
print 'koekoek'""", 9)
self.assertEqual("""import random
for i in range(int(5)):
print('koekoek')""",result)

def test_repeat_multiple_lines(self):
result = hedy.transpile("""repeat 5 times
print 'annemaria'
print 'koekoek'""", 9)

self.assertEqual("""import random
for i in range(int(5)):
print('annemaria')
print('koekoek')""", result)

def test_repeat_with_variable_print(self):
result = hedy.transpile("n is 5\nrepeat n times\n print 'me wants a cookie!'", 9)
self.assertEqual(result, """import random
n = '5'
for i in range(int(n)):
print('me wants a cookie!')""")
self.assertEqual(run_code(result),
'me wants a cookie!\nme wants a cookie!\nme wants a cookie!\nme wants a cookie!\nme wants a cookie!')

# todo: here we have to end in a newline, needs to be fixed!
def test_if_nested_in_if(self):
code="""kleur is groen
Expand All @@ -1204,19 +1112,6 @@ def test_if_nested_in_if(self):
if str(kleur2) == str('rood'):
print('mooi')""", result)


#todo: here we have to end in a newline, needs to be fixed!
def test_repeat_nested_in_if(self):
result = hedy.transpile("""kleur is groen
if kleur is groen:
repeat 3 times
print 'mooi'""", 9)
self.assertEqual(result, """import random
kleur = 'groen'
if str(kleur) == str('groen'):
for i in range(int(3)):
print('mooi')""")

def test_if_else(self):
result = hedy.transpile("""antwoord is ask Hoeveel is 10 plus 10?
if antwoord is 20:
Expand All @@ -1235,15 +1130,6 @@ def test_if_else(self):
print('Foutje')
print('Het antwoord moest zijn '+str(antwoord))""",result)

def test_repeat_basic_print(self):
result = hedy.transpile("""repeat 5 times
print 'me wants a cookie!'""", 9)
self.assertEqual(result, """import random
for i in range(int(5)):
print('me wants a cookie!')""")
self.assertEqual(run_code(result),'me wants a cookie!\nme wants a cookie!\nme wants a cookie!\nme wants a cookie!\nme wants a cookie!')


def test_print_random(self):
result = hedy.transpile("""keuzes is steen, schaar, papier
computerkeuze is keuzes at random
Expand All @@ -1254,34 +1140,6 @@ def test_print_random(self):
print('computer koos '+str(computerkeuze))""", result)


def test_repeat_basic_print_multiple_lines(self):
result = hedy.transpile("""repeat 5 times
print 'cookieeee!'
print 'me wants a cookie!'""", 9)
self.assertEqual("""import random
for i in range(int(5)):
print('cookieeee!')
print('me wants a cookie!')""", result)
# self.assertEqual(run_code(result),'cookieeee!\nme wants a cookie!\ncookieeee!\nme wants a cookie!\ncookieeee!\nme wants a cookie!\ncookieeee!\nme wants a cookie!\ncookieeee!\nme wants a cookie!')

def test_if_repeat_combined_else(self):
result = hedy.transpile("""kleur is ask Wat is je lievelingskleur?
if kleur is groen:
repeat 3 times
print 'mooi!'
else:
repeat 5 times
print 'niet zo mooi'""", 9)
self.assertEqual("""import random
kleur = input('Wat is je lievelingskleur?')
if str(kleur) == str('groen'):
for i in range(int(3)):
print('mooi!')
else:
for i in range(int(5)):
print('niet zo mooi')""", result)


if __name__ == '__main__':
unittest.main()

Expand Down
35 changes: 0 additions & 35 deletions tests/tests_level_08.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,6 @@ def test_if_with_indent(self):
if str(naam) == str('Hedy'):
print('koekoek')""", result)

def test_repeat_with_indent(self):
result = hedy.transpile("""repeat 5 times
print 'koekoek'""", 8)
self.assertEqual("""import random
for i in range(int(5)):
print('koekoek')""", result)

def test_repeat_with_variable_print(self):
result = hedy.transpile("n is 5\nrepeat n times\n print 'me wants a cookie!'", 8)
self.assertEqual(result, """import random
n = '5'
for i in range(int(n)):
print('me wants a cookie!')""")
self.assertEqual(run_code(result),
'me wants a cookie!\nme wants a cookie!\nme wants a cookie!\nme wants a cookie!\nme wants a cookie!')

def test_repeat_nested_in_if(self):
result = hedy.transpile("""kleur is groen
if kleur is groen
repeat 3 times
print 'mooi'""", 8)
self.assertEqual(result, """import random
kleur = 'groen'
if str(kleur) == str('groen'):
for i in range(int(3)):
print('mooi')""")

def test_if_else(self):
result = hedy.transpile("""antwoord is ask Hoeveel is 10 plus 10?
Expand All @@ -102,15 +76,6 @@ def test_if_else(self):
print('Foutje')
print('Het antwoord moest zijn '+str(antwoord))""", result)

def test_repeat_basic_print(self):
result = hedy.transpile("""repeat 5 times
print 'me wants a cookie!'""", 8)
self.assertEqual(result, """import random
for i in range(int(5)):
print('me wants a cookie!')""")
self.assertEqual(run_code(result),
'me wants a cookie!\nme wants a cookie!\nme wants a cookie!\nme wants a cookie!\nme wants a cookie!')

def test_print_random(self):
result = hedy.transpile("""keuzes is steen, schaar, papier
computerkeuze is keuzes at random
Expand Down
35 changes: 0 additions & 35 deletions tests/tests_level_09.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,6 @@ def test_if_with_indent(self):
if str(naam) == str('Hedy'):
print('koekoek')""", result)

def test_repeat_with_indent(self):
result = hedy.transpile("""repeat 5 times
print 'koekoek'""", 9)
self.assertEqual("""import random
for i in range(int(5)):
print('koekoek')""", result)

def test_repeat_with_variable_print(self):
result = hedy.transpile("n is 5\nrepeat n times\n print 'me wants a cookie!'", 9)
self.assertEqual(result, """import random
n = '5'
for i in range(int(n)):
print('me wants a cookie!')""")
self.assertEqual(run_code(result),
'me wants a cookie!\nme wants a cookie!\nme wants a cookie!\nme wants a cookie!\nme wants a cookie!')

def test_repeat_nested_in_if(self):
result = hedy.transpile("""kleur is groen
if kleur is groen:
repeat 3 times
print 'mooi'""", 9)
self.assertEqual(result, """import random
kleur = 'groen'
if str(kleur) == str('groen'):
for i in range(int(3)):
print('mooi')""")

def test_if_else(self):
result = hedy.transpile("""antwoord is ask Hoeveel is 10 plus 10?
if antwoord is 20:
Expand All @@ -102,14 +75,6 @@ def test_if_else(self):
print('Foutje')
print('Het antwoord moest zijn '+str(antwoord))""", result)

def test_repeat_basic_print(self):
result = hedy.transpile("""repeat 5 times
print 'me wants a cookie!'""", 9)
self.assertEqual(result, """import random
for i in range(int(5)):
print('me wants a cookie!')""")
self.assertEqual(run_code(result),
'me wants a cookie!\nme wants a cookie!\nme wants a cookie!\nme wants a cookie!\nme wants a cookie!')

def test_print_random(self):
result = hedy.transpile("""keuzes is steen, schaar, papier
Expand Down
4 changes: 2 additions & 2 deletions tests/tests_multiple_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def run_code(code):
#

class TestsForMultipleLevels(unittest.TestCase):
max_level = 8
max_level = 9

def test_print_with_list_var_random(self):
min_level = 2
Expand All @@ -41,7 +41,7 @@ def test_print_with_list_var_random(self):
print('Passed at level ', i)

min_level = 6
max_level = 8
max_level = 9
for i in range(min_level, max_level + 1):
result = hedy.transpile("dieren is Hond, Kat, Kangoeroe\nprint dieren at random", i)
self.assertEqual(result, "import random\ndieren = ['Hond', 'Kat', 'Kangoeroe']\nprint(str(random.choice(dieren)))")
Expand Down

0 comments on commit 77d0f43

Please sign in to comment.