Skip to content

Commit c6b2e10

Browse files
Refactor some exercise generators (#85)
Add instructions for `proverb` exercise.
1 parent 6581182 commit c6b2e10

File tree

10 files changed

+29
-25
lines changed

10 files changed

+29
-25
lines changed

exercises/practice/atbash-cipher/test.fut

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ import "atbash_cipher"
8484
-- input { "zmlyhgzxovrhlugvmzhgvkkrmthglmv" }
8585
-- output { "anobstacleisoftenasteppingstone" }
8686

87+
-- encode boundary characters
88+
-- ==
89+
-- entry: test_encode
90+
-- input { "/09:@AMNZ[`amnz{" }
91+
-- output { "09znm aznma" }
92+
8793
entry test_encode (phrase: []u8): []u8 =
8894
encode phrase
8995

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Instructions append
2+
3+
## Input format
4+
5+
Each list of inputs is represented as a null-terminated string, with a newline character at the end of each input.
6+
7+
An example would be `"nail\nshoe\nhorse\nrider\nmessage\nbattle\nkingdom\n"`

generators/exercises/atbash_cipher.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def extra_cases_disabled():
1+
def extra_cases():
22
return [
33
{
44
"description": "encode boundary characters",
@@ -14,9 +14,8 @@ def gen_test_case(prop, description, inp, expected, f):
1414
f.write(f"-- {description}\n")
1515
f.write("-- ==\n")
1616
f.write(f"-- entry: test_{prop}\n")
17-
f.write("-- input {" + f' "{phrase}" ' + "}\n")
18-
f.write("-- output {" + f' "{expected}" ' + "}\n\n")
19-
# f.write(f'-- output: { "{expected}" }\n\n')
17+
f.write(f'-- input {{ "{phrase}" }}\n')
18+
f.write(f'-- output {{ "{expected}" }}\n\n')
2019

2120

2221
def gen_main(f):

generators/exercises/pig_latin.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,8 @@ def gen_test_case(prop, description, inp, expected, f):
33

44
f.write(f"-- {description}\n")
55
f.write("-- ==\n")
6-
f.write("-- input {" + f' "{phrase}" ' + "}\n")
7-
f.write("-- output {" + f' "{expected}" ' + "}\n\n")
8-
9-
10-
def gen_true_test_case(prop, description, inp, expected, f):
11-
phrase = inp["phrase"]
12-
f.write(f"-- {description}\n")
13-
f.write("-- ==\n")
14-
f.write("-- input {" + f' "{phrase}" ' + "}\n")
15-
f.write("-- output {" + f' "{expected}" ' + "}\n\n")
6+
f.write(f'-- input {{ "{phrase}" }}\n')
7+
f.write(f'-- output {{ "{expected}" }}\n\n')
168

179

1810
def gen_main(f):

generators/exercises/transpose.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def rectangular(lines):
1111

1212
f.write(f"-- {description}\n")
1313
f.write("-- ==\n")
14-
f.write("-- input { " + lines + " }\n")
15-
f.write("-- output { " + expected + " }\n\n")
14+
f.write(f"-- input {{ {lines} }}\n")
15+
f.write(f"-- output {{ {expected} }}\n\n")
1616

1717

1818
def gen_main(f):

generators/exercises/twelve_days.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ def gen_test_case(prop, description, inp, expected, f):
55

66
f.write(f"-- {description}\n")
77
f.write("-- ==\n")
8-
f.write("-- input {" + f" {start_verse} {end_verse} " + "}\n")
9-
f.write("-- output {" + f' "{expected}" ' + "}\n\n")
8+
f.write(f"-- input {{ {start_verse} {end_verse} }}\n")
9+
f.write(f'-- output {{ "{expected}" }}\n\n')
1010

1111

1212
def gen_main(f):

generators/exercises/variable_length_quantity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ def serialize(message):
1212
f.write(f"-- {description}\n")
1313
f.write("-- ==\n")
1414
f.write(f"-- entry: test_{prop}\n")
15-
f.write("-- input {" + f" {integers} " + "}\n")
15+
f.write(f"-- input {{ {integers} }}\n")
1616
if isinstance(expected, dict):
1717
f.write("-- error: Error*\n\n")
1818
else:
1919
expected = serialize(expected)
20-
f.write("-- output {" + f" {expected} " + "}\n\n")
20+
f.write(f"-- output {{ {expected} }}\n\n")
2121

2222

2323
def gen_main(f):

generators/exercises/wordy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ def gen_test_case(prop, description, inp, expected, f):
33

44
f.write(f"-- {description}\n")
55
f.write("-- ==\n")
6-
f.write("-- input {" + f' "{question}" ' + "}\n")
6+
f.write(f'-- input {{ "{question}" }}\n')
77

88
if isinstance(expected, dict):
99
f.write("-- error: Error*\n\n")
1010
else:
11-
f.write("-- output {" + f" {expected} " + "}\n\n")
11+
f.write(f"-- output {{ {expected} }}\n\n")
1212

1313

1414
def gen_main(f):

generators/exercises/yacht.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ def gen_test_case(prop, description, inp, expected, f):
44

55
f.write(f"-- {description}\n")
66
f.write("-- ==\n")
7-
f.write("-- input {" + f' {dice} "{category}" ' + "}\n")
8-
f.write("-- output {" + f" {expected} " + "}\n\n")
7+
f.write(f'-- input {{ {dice} "{category}" }}\n')
8+
f.write(f"-- output {{ {expected} }}\n\n")
99

1010

1111
def gen_main(f):

generators/exercises/zebra_puzzle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def gen_test_case(prop, description, inp, expected, f):
33
f.write("-- ==\n")
44
f.write(f"-- entry: test_{prop}\n")
55
f.write("-- input {}\n")
6-
f.write("-- output {" + f' "{expected}" ' + "}\n\n")
6+
f.write(f'-- output {{ "{expected}" }}\n\n')
77

88

99
def gen_main(f):

0 commit comments

Comments
 (0)