diff --git a/exercises/practice/grains/test.fut b/exercises/practice/grains/test.fut index df2d130..25657e7 100644 --- a/exercises/practice/grains/test.fut +++ b/exercises/practice/grains/test.fut @@ -1,66 +1,66 @@ import "grains" --- Grains on square 1 +-- grains on square 1 -- == -- entry: test_square -- input { 1 } -- output { 1u64 } --- Grains on square 2 +-- grains on square 2 -- == -- entry: test_square -- input { 2 } -- output { 2u64 } --- Grains on square 3 +-- grains on square 3 -- == -- entry: test_square -- input { 3 } -- output { 4u64 } --- Grains on square 4 +-- grains on square 4 -- == -- entry: test_square -- input { 4 } -- output { 8u64 } --- Grains on square 16 +-- grains on square 16 -- == -- entry: test_square -- input { 16 } -- output { 32768u64 } --- Grains on square 32 +-- grains on square 32 -- == -- entry: test_square -- input { 32 } -- output { 2147483648u64 } --- Grains on square 64 +-- grains on square 64 -- == -- entry: test_square -- input { 64 } -- output { 9223372036854775808u64 } --- Square 0 is invalid +-- square 0 is invalid -- == -- entry: test_square -- input { 0 } -- error: Error* --- Negative square is invalid +-- negative square is invalid -- == -- entry: test_square -- input { -1 } -- error: Error* --- Square greater than 64 is invalid +-- square greater than 64 is invalid -- == -- entry: test_square -- input { 65 } -- error: Error* --- Returns the total number of grains on the board +-- returns the total number of grains on the board -- == -- entry: test_total -- input { 42 } diff --git a/exercises/practice/hamming/test.fut b/exercises/practice/hamming/test.fut index 098abcc..36b3232 100644 --- a/exercises/practice/hamming/test.fut +++ b/exercises/practice/hamming/test.fut @@ -1,46 +1,46 @@ import "hamming" --- Empty strands +-- empty strands -- == -- input { "" "" } -- output { 0 } --- Single letter identical strands +-- single letter identical strands -- == -- input { "A" "A" } -- output { 0 } --- Single letter different strands +-- single letter different strands -- == -- input { "G" "T" } -- output { 1 } --- Long identical strands +-- long identical strands -- == -- input { "GGACTGAAATCTG" "GGACTGAAATCTG" } -- output { 0 } --- Long different strands +-- long different strands -- == -- input { "GGACGGATTCTG" "AGGACGGATTCT" } -- output { 9 } --- Disallow first strand longer +-- disallow first strand longer -- == -- input { "AATG" "AAA" } -- error: Error* --- Disallow second strand longer +-- disallow second strand longer -- == -- input { "ATA" "AGTG" } -- error: Error* --- Disallow empty first strand +-- disallow empty first strand -- == -- input { "" "G" } -- error: Error* --- Disallow empty second strand +-- disallow empty second strand -- == -- input { "G" "" } -- error: Error* diff --git a/exercises/practice/high-scores/.meta/tests.toml b/exercises/practice/high-scores/.meta/tests.toml index 3cda0c8..19d69b4 100644 --- a/exercises/practice/high-scores/.meta/tests.toml +++ b/exercises/practice/high-scores/.meta/tests.toml @@ -37,12 +37,16 @@ include = false [2df075f9-fec9-4756-8f40-98c52a11504f] description = "Top 3 scores -> Latest score after personal top scores" +include = false [809c4058-7eb1-4206-b01e-79238b9b71bc] description = "Top 3 scores -> Scores after personal top scores" +include = false [ddb0efc0-9a86-4f82-bc30-21ae0bdc6418] description = "Top 3 scores -> Latest score after personal best" +include = false [6a0fd2d1-4cc4-46b9-a5bb-2fb667ca2364] description = "Top 3 scores -> Scores after personal best" +include = false diff --git a/exercises/practice/isogram/test.fut b/exercises/practice/isogram/test.fut index 37d7ecd..cca7278 100644 --- a/exercises/practice/isogram/test.fut +++ b/exercises/practice/isogram/test.fut @@ -1,71 +1,71 @@ import "isogram" --- Empty string +-- empty string -- == -- input { "" } -- output { true } --- Isogram with only lower case characters +-- isogram with only lower case characters -- == -- input { "isogram" } -- output { true } --- Word with one duplicated character +-- word with one duplicated character -- == -- input { "eleven" } -- output { false } --- Word with one duplicated character from the end of the alphabet +-- word with one duplicated character from the end of the alphabet -- == -- input { "zzyzx" } -- output { false } --- Longest reported english isogram +-- longest reported english isogram -- == -- input { "subdermatoglyphic" } -- output { true } --- Word with duplicated character in mixed case +-- word with duplicated character in mixed case -- == -- input { "Alphabet" } -- output { false } --- Word with duplicated character in mixed case, lowercase first +-- word with duplicated character in mixed case, lowercase first -- == -- input { "alphAbet" } -- output { false } --- Hypothetical isogrammic word with hyphen +-- hypothetical isogrammic word with hyphen -- == -- input { "thumbscrew-japingly" } -- output { true } --- Hypothetical word with duplicated character following hyphen +-- hypothetical word with duplicated character following hyphen -- == -- input { "thumbscrew-jappingly" } -- output { false } --- Isogram with duplicated hyphen +-- isogram with duplicated hyphen -- == -- input { "six-year-old" } -- output { true } --- Made-up name that is an isogram +-- made-up name that is an isogram -- == -- input { "Emily Jung Schwartzkopf" } -- output { true } --- Duplicated character in the middle +-- duplicated character in the middle -- == -- input { "accentor" } -- output { false } --- Same first and last characters +-- same first and last characters -- == -- input { "angola" } -- output { false } --- Word with duplicated character and with two hyphens +-- word with duplicated character and with two hyphens -- == -- input { "up-to-date" } -- output { false } diff --git a/exercises/practice/leap/test.fut b/exercises/practice/leap/test.fut index 78a9807..18ef89d 100644 --- a/exercises/practice/leap/test.fut +++ b/exercises/practice/leap/test.fut @@ -1,46 +1,46 @@ import "leap" --- Year not divisible by 4 in common year +-- year not divisible by 4 in common year -- == -- input { 2015 } -- output { false } --- Year divisible by 2, not divisible by 4 in common year +-- year divisible by 2, not divisible by 4 in common year -- == -- input { 1970 } -- output { false } --- Year divisible by 4, not divisible by 100 in leap year +-- year divisible by 4, not divisible by 100 in leap year -- == -- input { 1996 } -- output { true } --- Year divisible by 4 and 5 is still a leap year +-- year divisible by 4 and 5 is still a leap year -- == -- input { 1960 } -- output { true } --- Year divisible by 100, not divisible by 400 in common year +-- year divisible by 100, not divisible by 400 in common year -- == -- input { 2100 } -- output { false } --- Year divisible by 100 but not by 3 is still not a leap year +-- year divisible by 100 but not by 3 is still not a leap year -- == -- input { 1900 } -- output { false } --- Year divisible by 400 is leap year +-- year divisible by 400 is leap year -- == -- input { 2000 } -- output { true } --- Year divisible by 400 but not by 125 is still a leap year +-- year divisible by 400 but not by 125 is still a leap year -- == -- input { 2400 } -- output { true } --- Year divisible by 200, not divisible by 400 in common year +-- year divisible by 200, not divisible by 400 in common year -- == -- input { 1800 } -- output { false } diff --git a/exercises/practice/pangram/test.fut b/exercises/practice/pangram/test.fut index 0889c4c..fc33354 100644 --- a/exercises/practice/pangram/test.fut +++ b/exercises/practice/pangram/test.fut @@ -1,54 +1,54 @@ import "pangram" --- Empty sentence +-- empty sentence -- == -- input { "" } -- output { false } --- Perfect lower case +-- perfect lower case -- == -- input { "abcdefghijklmnopqrstuvwxyz" } -- output { true } --- Only lower case +-- only lower case -- == -- input { "the quick brown fox jumps over the lazy dog" } -- output { true } --- Missing the letter 'x' +-- missing the letter 'x' -- == -- input { "a quick movement of the enemy will jeopardize five gunboats" } -- output { false } --- Missing the letter 'h' +-- missing the letter 'h' -- == -- input { "five boxing wizards jump quickly at it" } -- output { false } --- With underscores +-- with underscores -- == -- input { "the_quick_brown_fox_jumps_over_the_lazy_dog" } -- output { true } --- With numbers +-- with numbers -- == -- input { "the 1 quick brown fox jumps over the 2 lazy dogs" } -- output { true } --- Missing letters replaced by numbers +-- missing letters replaced by numbers -- == -- input { "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog" } -- output { false } --- Mixed case and punctuation +-- mixed case and punctuation -- == -- input { "\"Five quacking Zephyrs jolt my wax bed.\"" } -- output { true } --- A-m and A-M are 26 different characters but not a pangram +-- a-m and A-M are 26 different characters but not a pangram -- == -- input { "abcdefghijklm ABCDEFGHIJKLM" } -- output { false } let main (sentence: []u8): bool = - is_pangram sentence \ No newline at end of file + is_pangram sentence diff --git a/generators/exercises/grains.py b/generators/exercises/grains.py new file mode 100644 index 0000000..b6f3d18 --- /dev/null +++ b/generators/exercises/grains.py @@ -0,0 +1,28 @@ +MAIN = """\ +entry test_square (n: i32): u64 = + square n + +entry test_total (_n: i32): u64 = + total () +""" + + +def gen_test_case(prop, description, inp, expected, f): + if prop == "total": + square = 42 + else: + square = inp["square"] + + f.write(f"-- {description}\n") + f.write("-- ==\n") + f.write(f"-- entry: test_{prop}\n") + f.write(f"-- input {{ {square} }}\n") + + if isinstance(expected, dict): + f.write("-- error: Error*\n\n") + else: + f.write(f"-- output {{ {expected}u64 }}\n\n") + + +def gen_main(f): + f.write(MAIN) diff --git a/generators/exercises/hamming.py b/generators/exercises/hamming.py new file mode 100644 index 0000000..024e7e1 --- /dev/null +++ b/generators/exercises/hamming.py @@ -0,0 +1,17 @@ +def gen_test_case(prop, description, inp, expected, f): + strand1 = inp["strand1"] + strand2 = inp["strand2"] + + f.write(f"-- {description}\n") + f.write("-- ==\n") + f.write(f'-- input {{ "{strand1}" "{strand2}" }}\n') + + if isinstance(expected, dict): + f.write("-- error: Error*\n\n") + else: + f.write(f"-- output {{ {expected} }}\n\n") + + +def gen_main(f): + f.write("let main (strand1: []u8) (strand2: []u8): i32 =\n") + f.write(" distance strand1 strand2\n") diff --git a/generators/exercises/hello_world.py b/generators/exercises/hello_world.py new file mode 100644 index 0000000..2a6af60 --- /dev/null +++ b/generators/exercises/hello_world.py @@ -0,0 +1,10 @@ +def gen_test_case(prop, description, inp, expected, f): + f.write(f"-- {description}\n") + f.write("-- ==\n") + f.write("-- input { 42 }\n") + f.write(f'-- output {{ "{expected}" }}\n\n') + + +def gen_main(f): + f.write("let main (_n: i32): []u8 =\n") + f.write(" copy hello\n") diff --git a/generators/exercises/high_scores.py b/generators/exercises/high_scores.py new file mode 100644 index 0000000..23ce1c3 --- /dev/null +++ b/generators/exercises/high_scores.py @@ -0,0 +1,26 @@ +MAIN = """\ +entry test_scores [n] (values: [n]i32): [n]i32 = + scores values + +entry test_latest (values: []i32): i32 = + latest values + +entry test_personal_best (values: []i32): i32 = + personal_best values + +entry test_personal_top_three (values: []i32): [3]i32 = + personal_top_three values +""" + + +def gen_test_case(prop, description, inp, expected, f): + values = inp["scores"] + f.write(f"-- {description}\n") + f.write("-- ==\n") + f.write(f"-- entry: test_{prop}\n") + f.write(f"-- input {{ {values} }}\n") + f.write(f"-- output {{ {expected} }}\n\n") + + +def gen_main(f): + f.write(MAIN) diff --git a/generators/exercises/isogram.py b/generators/exercises/isogram.py new file mode 100644 index 0000000..97495ca --- /dev/null +++ b/generators/exercises/isogram.py @@ -0,0 +1,13 @@ +def gen_test_case(prop, description, inp, expected, f): + expected = str(expected).lower() + phrase = inp["phrase"].replace('"', '\\"') + + f.write(f"-- {description}\n") + f.write("-- ==\n") + f.write(f'-- input {{ "{phrase}" }}\n') + f.write(f"-- output {{ {expected} }}\n\n") + + +def gen_main(f): + f.write("let main (phrase: []u8): bool =\n") + f.write(" is_isogram phrase\n") diff --git a/generators/exercises/leap.py b/generators/exercises/leap.py new file mode 100644 index 0000000..1a6769a --- /dev/null +++ b/generators/exercises/leap.py @@ -0,0 +1,12 @@ +def gen_test_case(prop, description, inp, expected, f): + expected = str(expected).lower() + year = inp["year"] + f.write(f"-- {description}\n") + f.write("-- ==\n") + f.write(f"-- input {{ {year} }}\n") + f.write(f"-- output {{ {expected} }}\n\n") + + +def gen_main(f): + f.write("let main (year: i32): bool =\n") + f.write(" is_leap year\n") diff --git a/generators/exercises/pangram.py b/generators/exercises/pangram.py new file mode 100644 index 0000000..4336d8b --- /dev/null +++ b/generators/exercises/pangram.py @@ -0,0 +1,13 @@ +def gen_test_case(prop, description, inp, expected, f): + expected = str(expected).lower() + sentence = inp["sentence"].replace('"', '\\"') + + f.write(f"-- {description}\n") + f.write("-- ==\n") + f.write(f'-- input {{ "{sentence}" }}\n') + f.write(f"-- output {{ {expected} }}\n\n") + + +def gen_main(f): + f.write("let main (sentence: []u8): bool =\n") + f.write(" is_pangram sentence\n") diff --git a/generators/exercises/perfect_numbers.py b/generators/exercises/perfect_numbers.py new file mode 100644 index 0000000..c754abf --- /dev/null +++ b/generators/exercises/perfect_numbers.py @@ -0,0 +1,14 @@ +def gen_test_case(prop, description, inp, expected, f): + number = inp["number"] + f.write(f"-- {description}\n") + f.write("-- ==\n") + f.write(f"-- input {{ {number} }}\n") + if isinstance(expected, dict): + f.write("-- error: Error*\n\n") + else: + f.write(f'-- output {{ "{expected.title()}" }}\n\n') + + +def gen_main(f): + f.write("let main (number: i32): []u8 =\n") + f.write(" classify number\n")