diff --git a/exercises/practice/largest-series-product/test.fut b/exercises/practice/largest-series-product/test.fut index 4712074..f1dabf1 100644 --- a/exercises/practice/largest-series-product/test.fut +++ b/exercises/practice/largest-series-product/test.fut @@ -1,66 +1,76 @@ import "largest_series_product" --- Finds the largest product if span equals length +-- finds the largest product if span equals length -- == -- input { "29" 2 } -- output { 18 } --- Can find the largest product of 2 with numbers in order +-- can find the largest product of 2 with numbers in order -- == -- input { "0123456789" 2 } -- output { 72 } --- Can find the largest product of 2 +-- can find the largest product of 2 -- == -- input { "576802143" 2 } -- output { 48 } --- Can find the largest product of 3 with numbers in order +-- can find the largest product of 3 with numbers in order -- == -- input { "0123456789" 3 } -- output { 504 } --- Can find the largest product of 3 +-- can find the largest product of 3 -- == -- input { "1027839564" 3 } -- output { 270 } --- Can find the largest product of 5 with numbers in order +-- can find the largest product of 5 with numbers in order -- == -- input { "0123456789" 5 } -- output { 15120 } --- Can get the largest product of a big number +-- can get the largest product of a big number -- == -- input { "73167176531330624919225119674426574742355349194934" 6 } -- output { 23520 } --- Reports zero if the only digits are zero +-- reports zero if the only digits are zero -- == -- input { "0000" 2 } -- output { 0 } --- Reports zero if all spans include zero +-- reports zero if all spans include zero -- == -- input { "99099" 3 } -- output { 0 } --- Rejects span longer than string length +-- rejects span longer than string length -- == -- input { "123" 4 } -- error: Error* --- Rejects empty string and nonzero span +-- reports 1 for empty string and empty product (0 span) +-- == +-- input { "" 0 } +-- output { 1 } + +-- reports 1 for nonempty string and empty product (0 span) +-- == +-- input { "123" 0 } +-- output { 1 } + +-- rejects empty string and nonzero span -- == -- input { "" 1 } -- error: Error* --- Rejects invalid character in digits +-- rejects invalid character in digits -- == -- input { "1234a5" 2 } -- error: Error* --- Rejects negative span +-- rejects negative span -- == -- input { "12345" -1 } -- error: Error* diff --git a/generators/exercises/largest_series_product.py b/generators/exercises/largest_series_product.py new file mode 100644 index 0000000..06e3154 --- /dev/null +++ b/generators/exercises/largest_series_product.py @@ -0,0 +1,15 @@ +def gen_test_case(prop, description, inp, expected, f): + digits = inp["digits"] + span = inp["span"] + f.write(f"-- {description}\n") + f.write("-- ==\n") + f.write(f'-- input {{ "{digits}" {span} }}\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 (digits: []u8) (span: i32) : i32 =\n") + f.write(" largest_product digits span\n")