Skip to content

Commit 6bdfa88

Browse files
generate 8 tests (#99)
[no important files changed]
1 parent 2e810e3 commit 6bdfa88

File tree

14 files changed

+191
-54
lines changed

14 files changed

+191
-54
lines changed

exercises/practice/grains/test.fut

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
11
import "grains"
22

3-
-- Grains on square 1
3+
-- grains on square 1
44
-- ==
55
-- entry: test_square
66
-- input { 1 }
77
-- output { 1u64 }
88

9-
-- Grains on square 2
9+
-- grains on square 2
1010
-- ==
1111
-- entry: test_square
1212
-- input { 2 }
1313
-- output { 2u64 }
1414

15-
-- Grains on square 3
15+
-- grains on square 3
1616
-- ==
1717
-- entry: test_square
1818
-- input { 3 }
1919
-- output { 4u64 }
2020

21-
-- Grains on square 4
21+
-- grains on square 4
2222
-- ==
2323
-- entry: test_square
2424
-- input { 4 }
2525
-- output { 8u64 }
2626

27-
-- Grains on square 16
27+
-- grains on square 16
2828
-- ==
2929
-- entry: test_square
3030
-- input { 16 }
3131
-- output { 32768u64 }
3232

33-
-- Grains on square 32
33+
-- grains on square 32
3434
-- ==
3535
-- entry: test_square
3636
-- input { 32 }
3737
-- output { 2147483648u64 }
3838

39-
-- Grains on square 64
39+
-- grains on square 64
4040
-- ==
4141
-- entry: test_square
4242
-- input { 64 }
4343
-- output { 9223372036854775808u64 }
4444

45-
-- Square 0 is invalid
45+
-- square 0 is invalid
4646
-- ==
4747
-- entry: test_square
4848
-- input { 0 }
4949
-- error: Error*
5050

51-
-- Negative square is invalid
51+
-- negative square is invalid
5252
-- ==
5353
-- entry: test_square
5454
-- input { -1 }
5555
-- error: Error*
5656

57-
-- Square greater than 64 is invalid
57+
-- square greater than 64 is invalid
5858
-- ==
5959
-- entry: test_square
6060
-- input { 65 }
6161
-- error: Error*
6262

63-
-- Returns the total number of grains on the board
63+
-- returns the total number of grains on the board
6464
-- ==
6565
-- entry: test_total
6666
-- input { 42 }

exercises/practice/hamming/test.fut

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
import "hamming"
22

3-
-- Empty strands
3+
-- empty strands
44
-- ==
55
-- input { "" "" }
66
-- output { 0 }
77

8-
-- Single letter identical strands
8+
-- single letter identical strands
99
-- ==
1010
-- input { "A" "A" }
1111
-- output { 0 }
1212

13-
-- Single letter different strands
13+
-- single letter different strands
1414
-- ==
1515
-- input { "G" "T" }
1616
-- output { 1 }
1717

18-
-- Long identical strands
18+
-- long identical strands
1919
-- ==
2020
-- input { "GGACTGAAATCTG" "GGACTGAAATCTG" }
2121
-- output { 0 }
2222

23-
-- Long different strands
23+
-- long different strands
2424
-- ==
2525
-- input { "GGACGGATTCTG" "AGGACGGATTCT" }
2626
-- output { 9 }
2727

28-
-- Disallow first strand longer
28+
-- disallow first strand longer
2929
-- ==
3030
-- input { "AATG" "AAA" }
3131
-- error: Error*
3232

33-
-- Disallow second strand longer
33+
-- disallow second strand longer
3434
-- ==
3535
-- input { "ATA" "AGTG" }
3636
-- error: Error*
3737

38-
-- Disallow empty first strand
38+
-- disallow empty first strand
3939
-- ==
4040
-- input { "" "G" }
4141
-- error: Error*
4242

43-
-- Disallow empty second strand
43+
-- disallow empty second strand
4444
-- ==
4545
-- input { "G" "" }
4646
-- error: Error*

exercises/practice/high-scores/.meta/tests.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ include = false
3737

3838
[2df075f9-fec9-4756-8f40-98c52a11504f]
3939
description = "Top 3 scores -> Latest score after personal top scores"
40+
include = false
4041

4142
[809c4058-7eb1-4206-b01e-79238b9b71bc]
4243
description = "Top 3 scores -> Scores after personal top scores"
44+
include = false
4345

4446
[ddb0efc0-9a86-4f82-bc30-21ae0bdc6418]
4547
description = "Top 3 scores -> Latest score after personal best"
48+
include = false
4649

4750
[6a0fd2d1-4cc4-46b9-a5bb-2fb667ca2364]
4851
description = "Top 3 scores -> Scores after personal best"
52+
include = false

exercises/practice/isogram/test.fut

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,71 @@
11
import "isogram"
22

3-
-- Empty string
3+
-- empty string
44
-- ==
55
-- input { "" }
66
-- output { true }
77

8-
-- Isogram with only lower case characters
8+
-- isogram with only lower case characters
99
-- ==
1010
-- input { "isogram" }
1111
-- output { true }
1212

13-
-- Word with one duplicated character
13+
-- word with one duplicated character
1414
-- ==
1515
-- input { "eleven" }
1616
-- output { false }
1717

18-
-- Word with one duplicated character from the end of the alphabet
18+
-- word with one duplicated character from the end of the alphabet
1919
-- ==
2020
-- input { "zzyzx" }
2121
-- output { false }
2222

23-
-- Longest reported english isogram
23+
-- longest reported english isogram
2424
-- ==
2525
-- input { "subdermatoglyphic" }
2626
-- output { true }
2727

28-
-- Word with duplicated character in mixed case
28+
-- word with duplicated character in mixed case
2929
-- ==
3030
-- input { "Alphabet" }
3131
-- output { false }
3232

33-
-- Word with duplicated character in mixed case, lowercase first
33+
-- word with duplicated character in mixed case, lowercase first
3434
-- ==
3535
-- input { "alphAbet" }
3636
-- output { false }
3737

38-
-- Hypothetical isogrammic word with hyphen
38+
-- hypothetical isogrammic word with hyphen
3939
-- ==
4040
-- input { "thumbscrew-japingly" }
4141
-- output { true }
4242

43-
-- Hypothetical word with duplicated character following hyphen
43+
-- hypothetical word with duplicated character following hyphen
4444
-- ==
4545
-- input { "thumbscrew-jappingly" }
4646
-- output { false }
4747

48-
-- Isogram with duplicated hyphen
48+
-- isogram with duplicated hyphen
4949
-- ==
5050
-- input { "six-year-old" }
5151
-- output { true }
5252

53-
-- Made-up name that is an isogram
53+
-- made-up name that is an isogram
5454
-- ==
5555
-- input { "Emily Jung Schwartzkopf" }
5656
-- output { true }
5757

58-
-- Duplicated character in the middle
58+
-- duplicated character in the middle
5959
-- ==
6060
-- input { "accentor" }
6161
-- output { false }
6262

63-
-- Same first and last characters
63+
-- same first and last characters
6464
-- ==
6565
-- input { "angola" }
6666
-- output { false }
6767

68-
-- Word with duplicated character and with two hyphens
68+
-- word with duplicated character and with two hyphens
6969
-- ==
7070
-- input { "up-to-date" }
7171
-- output { false }

exercises/practice/leap/test.fut

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
import "leap"
22

3-
-- Year not divisible by 4 in common year
3+
-- year not divisible by 4 in common year
44
-- ==
55
-- input { 2015 }
66
-- output { false }
77

8-
-- Year divisible by 2, not divisible by 4 in common year
8+
-- year divisible by 2, not divisible by 4 in common year
99
-- ==
1010
-- input { 1970 }
1111
-- output { false }
1212

13-
-- Year divisible by 4, not divisible by 100 in leap year
13+
-- year divisible by 4, not divisible by 100 in leap year
1414
-- ==
1515
-- input { 1996 }
1616
-- output { true }
1717

18-
-- Year divisible by 4 and 5 is still a leap year
18+
-- year divisible by 4 and 5 is still a leap year
1919
-- ==
2020
-- input { 1960 }
2121
-- output { true }
2222

23-
-- Year divisible by 100, not divisible by 400 in common year
23+
-- year divisible by 100, not divisible by 400 in common year
2424
-- ==
2525
-- input { 2100 }
2626
-- output { false }
2727

28-
-- Year divisible by 100 but not by 3 is still not a leap year
28+
-- year divisible by 100 but not by 3 is still not a leap year
2929
-- ==
3030
-- input { 1900 }
3131
-- output { false }
3232

33-
-- Year divisible by 400 is leap year
33+
-- year divisible by 400 is leap year
3434
-- ==
3535
-- input { 2000 }
3636
-- output { true }
3737

38-
-- Year divisible by 400 but not by 125 is still a leap year
38+
-- year divisible by 400 but not by 125 is still a leap year
3939
-- ==
4040
-- input { 2400 }
4141
-- output { true }
4242

43-
-- Year divisible by 200, not divisible by 400 in common year
43+
-- year divisible by 200, not divisible by 400 in common year
4444
-- ==
4545
-- input { 1800 }
4646
-- output { false }

exercises/practice/pangram/test.fut

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
import "pangram"
22

3-
-- Empty sentence
3+
-- empty sentence
44
-- ==
55
-- input { "" }
66
-- output { false }
77

8-
-- Perfect lower case
8+
-- perfect lower case
99
-- ==
1010
-- input { "abcdefghijklmnopqrstuvwxyz" }
1111
-- output { true }
1212

13-
-- Only lower case
13+
-- only lower case
1414
-- ==
1515
-- input { "the quick brown fox jumps over the lazy dog" }
1616
-- output { true }
1717

18-
-- Missing the letter 'x'
18+
-- missing the letter 'x'
1919
-- ==
2020
-- input { "a quick movement of the enemy will jeopardize five gunboats" }
2121
-- output { false }
2222

23-
-- Missing the letter 'h'
23+
-- missing the letter 'h'
2424
-- ==
2525
-- input { "five boxing wizards jump quickly at it" }
2626
-- output { false }
2727

28-
-- With underscores
28+
-- with underscores
2929
-- ==
3030
-- input { "the_quick_brown_fox_jumps_over_the_lazy_dog" }
3131
-- output { true }
3232

33-
-- With numbers
33+
-- with numbers
3434
-- ==
3535
-- input { "the 1 quick brown fox jumps over the 2 lazy dogs" }
3636
-- output { true }
3737

38-
-- Missing letters replaced by numbers
38+
-- missing letters replaced by numbers
3939
-- ==
4040
-- input { "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog" }
4141
-- output { false }
4242

43-
-- Mixed case and punctuation
43+
-- mixed case and punctuation
4444
-- ==
4545
-- input { "\"Five quacking Zephyrs jolt my wax bed.\"" }
4646
-- output { true }
4747

48-
-- A-m and A-M are 26 different characters but not a pangram
48+
-- a-m and A-M are 26 different characters but not a pangram
4949
-- ==
5050
-- input { "abcdefghijklm ABCDEFGHIJKLM" }
5151
-- output { false }
5252

5353
let main (sentence: []u8): bool =
54-
is_pangram sentence
54+
is_pangram sentence

generators/exercises/grains.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
MAIN = """\
2+
entry test_square (n: i32): u64 =
3+
square n
4+
5+
entry test_total (_n: i32): u64 =
6+
total ()
7+
"""
8+
9+
10+
def gen_test_case(prop, description, inp, expected, f):
11+
if prop == "total":
12+
square = 42
13+
else:
14+
square = inp["square"]
15+
16+
f.write(f"-- {description}\n")
17+
f.write("-- ==\n")
18+
f.write(f"-- entry: test_{prop}\n")
19+
f.write(f"-- input {{ {square} }}\n")
20+
21+
if isinstance(expected, dict):
22+
f.write("-- error: Error*\n\n")
23+
else:
24+
f.write(f"-- output {{ {expected}u64 }}\n\n")
25+
26+
27+
def gen_main(f):
28+
f.write(MAIN)

0 commit comments

Comments
 (0)