|
1 |
| -import org.scalatest.{Matchers, FlatSpec} |
| 1 | +import org.scalatest.{Matchers, FunSuite} |
2 | 2 |
|
3 |
| -class PalindromeProductsTest extends FlatSpec with Matchers { |
| 3 | +/** @version 1.0.0 */ |
| 4 | +class PalindromeProductsTest extends FunSuite with Matchers { |
4 | 5 |
|
5 |
| - it should "find smallest palindrome from a single digit factors" in { |
6 |
| - val (value, factors) = PalindromeProducts(1, 9).smallest |
7 |
| - value should be (1) |
8 |
| - factors should be (Set((1, 1))) |
| 6 | + // PalindromeProducts largest call is expecting a return type of |
| 7 | + // Option[(Int, Set[(Int, Int)])] - None is expected for error cases. |
| 8 | + // Some is expected for valid cases. The first element of the tuple |
| 9 | + // is the largest palindrome product value. The second element of the |
| 10 | + // tuple is the list of factors. |
| 11 | + // PalindromeProducts smallest call is expecting a return type of |
| 12 | + // Option[(Int, Set[(Int, Int)])] - None is expected for error cases. |
| 13 | + // Some is expected for valid cases. The first element of the tuple |
| 14 | + // is the smallest palindrome product value. The second element of the |
| 15 | + // tuple is the list of factors. |
| 16 | + |
| 17 | + test("finds the smallest palindrome from single digit factors") { |
| 18 | + PalindromeProducts(1, 9).smallest should be(Some((1, Set((1, 1))))) |
| 19 | + } |
| 20 | + |
| 21 | + test("finds the largest palindrome from single digit factors") { |
| 22 | + pending |
| 23 | + PalindromeProducts(1, 9).largest should be(Some((9, Set((1, 9), (3, 3))))) |
| 24 | + } |
| 25 | + |
| 26 | + test("find the smallest palindrome from double digit factors") { |
| 27 | + pending |
| 28 | + PalindromeProducts(10, 99).smallest should be(Some((121, Set((11, 11))))) |
| 29 | + } |
| 30 | + |
| 31 | + test("find the largest palindrome from double digit factors") { |
| 32 | + pending |
| 33 | + PalindromeProducts(10, 99).largest should be(Some((9009, Set((91, 99))))) |
| 34 | + } |
| 35 | + |
| 36 | + test("find smallest palindrome from triple digit factors") { |
| 37 | + pending |
| 38 | + PalindromeProducts(100, 999).smallest should be( |
| 39 | + Some((10201, Set((101, 101))))) |
9 | 40 | }
|
10 | 41 |
|
11 |
| - it should "find largest palindrome from a single digit factors" in { |
| 42 | + test("find the largest palindrome from triple digit factors") { |
12 | 43 | pending
|
13 |
| - val (value, factors) = PalindromeProducts(0, 9).largest |
14 |
| - value should be (9) |
15 |
| - factors should be (Set((1, 9), (3, 3))) |
| 44 | + PalindromeProducts(100, 999).largest should be( |
| 45 | + Some((906609, Set((913, 993))))) |
16 | 46 | }
|
17 | 47 |
|
18 |
| - it should "find smallest palindrome from a double digit factors" in { |
| 48 | + test("find smallest palindrome from four digit factors") { |
19 | 49 | pending
|
20 |
| - val (value, factors) = PalindromeProducts(10, 99).smallest |
21 |
| - value should be (121) |
22 |
| - factors should be (Set((11, 11))) |
| 50 | + PalindromeProducts(1000, 9999).smallest should be( |
| 51 | + Some((1002001, Set((1001, 1001))))) |
23 | 52 | }
|
24 | 53 |
|
25 |
| - it should "find largest palindrome from a double digit factors" in { |
| 54 | + test("find the largest palindrome from four digit factors") { |
26 | 55 | pending
|
27 |
| - val (value, factors) = PalindromeProducts(10, 99).largest |
28 |
| - value should be (9009) |
29 |
| - factors should be (Set((91, 99))) |
| 56 | + PalindromeProducts(1000, 9999).largest should be( |
| 57 | + Some((99000099, Set((9901, 9999))))) |
30 | 58 | }
|
31 | 59 |
|
32 |
| - it should "find smallest palindrome from a triple digit factors" in { |
| 60 | + test("empty result for smallest if no palindrome in the range") { |
33 | 61 | pending
|
34 |
| - val (value, factors) = PalindromeProducts(100, 999).smallest |
35 |
| - value should be (10201) |
36 |
| - factors should be (Set((101, 101))) |
| 62 | + PalindromeProducts(1002, 1003).smallest should be(None) |
37 | 63 | }
|
38 | 64 |
|
39 |
| - it should "find largest palindrome from a triple digit factors" in { |
| 65 | + test("empty result for largest if no palindrome in the range") { |
40 | 66 | pending
|
41 |
| - val (value, factors) = PalindromeProducts(100, 999).largest |
42 |
| - value should be (906609) |
43 |
| - factors should be (Set((913, 993))) |
| 67 | + PalindromeProducts(15, 15).largest should be(None) |
44 | 68 | }
|
45 | 69 |
|
46 |
| - it should "find smallest palindrome from a four digit factors" in { |
| 70 | + test("error result for smallest if min is more than max") { |
47 | 71 | pending
|
48 |
| - val (value, factors) = PalindromeProducts(1000, 9999).smallest |
49 |
| - value should be (1002001) |
50 |
| - factors should be (Set((1001, 1001))) |
| 72 | + PalindromeProducts(10000, 1).smallest should be(None) |
51 | 73 | }
|
52 | 74 |
|
53 |
| - it should "find largest palindrome from a four digit factors" in { |
| 75 | + test("error result for largest if min is more than max") { |
54 | 76 | pending
|
55 |
| - val (value, factors) = PalindromeProducts(1000, 9999).largest |
56 |
| - value should be (99000099) |
57 |
| - factors should be (Set((9901, 9999))) |
| 77 | + PalindromeProducts(2, 1).largest should be(None) |
58 | 78 | }
|
59 | 79 | }
|
0 commit comments