|
| 1 | +import "./largest-series-product" for Series |
| 2 | +import "wren-testie/testie" for Testie, Expect |
| 3 | + |
| 4 | +Testie.test("LargestSeriesProduct") { |do, skip| |
| 5 | + |
| 6 | + do.test("finds the largest product if span equals length") { |
| 7 | + var actual = Series.new("29", 2).largestProduct |
| 8 | + var expected = 18 |
| 9 | + Expect.value(actual).toEqual(expected) |
| 10 | + } |
| 11 | + |
| 12 | + skip.test("can find the largest product of 2 with numbers in order") { |
| 13 | + var actual = Series.new("0123456789", 2).largestProduct |
| 14 | + var expected = 72 |
| 15 | + Expect.value(actual).toEqual(expected) |
| 16 | + } |
| 17 | + |
| 18 | + skip.test("can find the largest product of 2") { |
| 19 | + var actual = Series.new("576802143", 2).largestProduct |
| 20 | + var expected = 48 |
| 21 | + Expect.value(actual).toEqual(expected) |
| 22 | + } |
| 23 | + |
| 24 | + skip.test("can find the largest product of 3 with numbers in order") { |
| 25 | + var actual = Series.new("0123456789", 3).largestProduct |
| 26 | + var expected = 504 |
| 27 | + Expect.value(actual).toEqual(expected) |
| 28 | + } |
| 29 | + |
| 30 | + skip.test("can find the largest product of 3") { |
| 31 | + var actual = Series.new("1027839564", 3).largestProduct |
| 32 | + var expected = 270 |
| 33 | + Expect.value(actual).toEqual(expected) |
| 34 | + } |
| 35 | + |
| 36 | + skip.test("can find the largest product of 5 with numbers in order") { |
| 37 | + var actual = Series.new("0123456789", 5).largestProduct |
| 38 | + var expected = 15120 |
| 39 | + Expect.value(actual).toEqual(expected) |
| 40 | + } |
| 41 | + |
| 42 | + skip.test("can get the largest product of a big number") { |
| 43 | + var actual = Series.new("73167176531330624919225119674426574742355349194934", 6).largestProduct |
| 44 | + var expected = 23520 |
| 45 | + Expect.value(actual).toEqual(expected) |
| 46 | + } |
| 47 | + |
| 48 | + skip.test("reports zero if the only digits are zero") { |
| 49 | + var actual = Series.new("0000", 2).largestProduct |
| 50 | + var expected = 0 |
| 51 | + Expect.value(actual).toEqual(expected) |
| 52 | + } |
| 53 | + |
| 54 | + skip.test("reports zero if all spans include zero") { |
| 55 | + var actual = Series.new("99099", 3).largestProduct |
| 56 | + var expected = 0 |
| 57 | + Expect.value(actual).toEqual(expected) |
| 58 | + } |
| 59 | + |
| 60 | + skip.test("rejects span longer than string length") { |
| 61 | + Expect.that { |
| 62 | + Series.new("123", 4).largestProduct |
| 63 | + }.abortsWith("span must be smaller than string length") |
| 64 | + } |
| 65 | + |
| 66 | + skip.test("reports 1 for empty string and empty product (0 span)") { |
| 67 | + var actual = Series.new("", 0).largestProduct |
| 68 | + var expected = 1 |
| 69 | + Expect.value(actual).toEqual(expected) |
| 70 | + } |
| 71 | + |
| 72 | + skip.test("reports 1 for nonempty string and empty product (0 span)") { |
| 73 | + var actual = Series.new("123", 0).largestProduct |
| 74 | + var expected = 1 |
| 75 | + Expect.value(actual).toEqual(expected) |
| 76 | + } |
| 77 | + |
| 78 | + skip.test("rejects empty string and nonzero span") { |
| 79 | + Expect.that { |
| 80 | + Series.new("", 1).largestProduct |
| 81 | + }.abortsWith("span must be smaller than string length") |
| 82 | + } |
| 83 | + |
| 84 | + skip.test("rejects invalid character in digits") { |
| 85 | + Expect.that { |
| 86 | + Series.new("1234a5", 2).largestProduct |
| 87 | + }.abortsWith("digits input must only contain digits") |
| 88 | + } |
| 89 | + |
| 90 | + skip.test("rejects negative span") { |
| 91 | + Expect.that { |
| 92 | + Series.new("12345", -1).largestProduct |
| 93 | + }.abortsWith("span must not be negative") |
| 94 | + } |
| 95 | +} |
0 commit comments