Skip to content

Commit 2eb2910

Browse files
generate largest-series-product tests (#98)
1 parent 6bdfa88 commit 2eb2910

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

exercises/practice/largest-series-product/test.fut

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

3-
-- Finds the largest product if span equals length
3+
-- finds the largest product if span equals length
44
-- ==
55
-- input { "29" 2 }
66
-- output { 18 }
77

8-
-- Can find the largest product of 2 with numbers in order
8+
-- can find the largest product of 2 with numbers in order
99
-- ==
1010
-- input { "0123456789" 2 }
1111
-- output { 72 }
1212

13-
-- Can find the largest product of 2
13+
-- can find the largest product of 2
1414
-- ==
1515
-- input { "576802143" 2 }
1616
-- output { 48 }
1717

18-
-- Can find the largest product of 3 with numbers in order
18+
-- can find the largest product of 3 with numbers in order
1919
-- ==
2020
-- input { "0123456789" 3 }
2121
-- output { 504 }
2222

23-
-- Can find the largest product of 3
23+
-- can find the largest product of 3
2424
-- ==
2525
-- input { "1027839564" 3 }
2626
-- output { 270 }
2727

28-
-- Can find the largest product of 5 with numbers in order
28+
-- can find the largest product of 5 with numbers in order
2929
-- ==
3030
-- input { "0123456789" 5 }
3131
-- output { 15120 }
3232

33-
-- Can get the largest product of a big number
33+
-- can get the largest product of a big number
3434
-- ==
3535
-- input { "73167176531330624919225119674426574742355349194934" 6 }
3636
-- output { 23520 }
3737

38-
-- Reports zero if the only digits are zero
38+
-- reports zero if the only digits are zero
3939
-- ==
4040
-- input { "0000" 2 }
4141
-- output { 0 }
4242

43-
-- Reports zero if all spans include zero
43+
-- reports zero if all spans include zero
4444
-- ==
4545
-- input { "99099" 3 }
4646
-- output { 0 }
4747

48-
-- Rejects span longer than string length
48+
-- rejects span longer than string length
4949
-- ==
5050
-- input { "123" 4 }
5151
-- error: Error*
5252

53-
-- Rejects empty string and nonzero span
53+
-- reports 1 for empty string and empty product (0 span)
54+
-- ==
55+
-- input { "" 0 }
56+
-- output { 1 }
57+
58+
-- reports 1 for nonempty string and empty product (0 span)
59+
-- ==
60+
-- input { "123" 0 }
61+
-- output { 1 }
62+
63+
-- rejects empty string and nonzero span
5464
-- ==
5565
-- input { "" 1 }
5666
-- error: Error*
5767

58-
-- Rejects invalid character in digits
68+
-- rejects invalid character in digits
5969
-- ==
6070
-- input { "1234a5" 2 }
6171
-- error: Error*
6272

63-
-- Rejects negative span
73+
-- rejects negative span
6474
-- ==
6575
-- input { "12345" -1 }
6676
-- error: Error*
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def gen_test_case(prop, description, inp, expected, f):
2+
digits = inp["digits"]
3+
span = inp["span"]
4+
f.write(f"-- {description}\n")
5+
f.write("-- ==\n")
6+
f.write(f'-- input {{ "{digits}" {span} }}\n')
7+
if isinstance(expected, dict):
8+
f.write("-- error: Error*\n\n")
9+
else:
10+
f.write(f"-- output {{ {expected} }}\n\n")
11+
12+
13+
def gen_main(f):
14+
f.write("let main (digits: []u8) (span: i32) : i32 =\n")
15+
f.write(" largest_product digits span\n")

0 commit comments

Comments
 (0)