|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
+import org.junit.Ignore;
|
|
|
2
|
+import org.junit.Test;
|
|
1
|
3
|
|
|
2
|
4
|
import java.util.Arrays;
|
|
3
|
5
|
import java.util.Collections;
|
|
4
|
6
|
import java.util.List;
|
|
5
|
7
|
import java.util.SortedMap;
|
|
6
|
8
|
import java.util.stream.Collectors;
|
|
7
|
|
-import static junit.framework.TestCase.assertEquals;
|
|
8
|
|
-import static junit.framework.TestCase.assertFalse;
|
|
9
|
|
-import static junit.framework.TestCase.assertNotNull;
|
|
10
|
|
-import org.junit.Ignore;
|
|
11
|
|
-import org.junit.Test;
|
|
|
9
|
+
|
|
|
10
|
+import static junit.framework.TestCase.*;
|
|
12
|
11
|
|
|
13
|
12
|
public class PalindromesTest {
|
|
14
|
13
|
|
|
|
@@ -22,22 +21,9 @@ public class PalindromesTest {
|
|
22
|
21
|
);
|
|
23
|
22
|
final long expectedValue = 9l;
|
|
24
|
23
|
|
|
25
|
|
- final SortedMap<Long, List<List<Integer>>> palindromes
|
|
26
|
|
- = Palindromes.getPalindromeSortedListBuilder()
|
|
27
|
|
- .withFactorsLessThanOrEqualTo(9).build();
|
|
28
|
|
-
|
|
29
|
|
- assertNotNull(palindromes);
|
|
30
|
|
- assertFalse(palindromes.isEmpty());
|
|
31
|
|
-
|
|
32
|
|
- long actualValue = palindromes.lastKey();
|
|
33
|
|
- assertEquals(expectedValue, actualValue);
|
|
|
24
|
+ final SortedMap<Long, List<List<Integer>>> palindromes = Palindromes.getPalindromeProductsWithFactors(1, 9);
|
|
34
|
25
|
|
|
35
|
|
- List<List<Integer>> actual = palindromes
|
|
36
|
|
- .get(palindromes.lastKey())
|
|
37
|
|
- .stream()
|
|
38
|
|
- .sorted((a, b) -> Integer.compare(a.get(0), b.get(0)))
|
|
39
|
|
- .collect(Collectors.toList());
|
|
40
|
|
- assertEquals(expected, actual);
|
|
|
26
|
+ checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.lastKey());
|
|
41
|
27
|
}
|
|
42
|
28
|
|
|
43
|
29
|
@Test
|
|
|
@@ -50,24 +36,9 @@ public class PalindromesTest {
|
|
50
|
36
|
);
|
|
51
|
37
|
final long expectedValue = 9009l;
|
|
52
|
38
|
|
|
53
|
|
- final SortedMap<Long, List<List<Integer>>> palindromes
|
|
54
|
|
- = Palindromes.getPalindromeSortedListBuilder()
|
|
55
|
|
- .withFactorsLessThanOrEqualTo(99)
|
|
56
|
|
- .withFactorsGreaterThanOrEqualTo(10)
|
|
57
|
|
- .build();
|
|
58
|
|
-
|
|
59
|
|
- assertNotNull(palindromes);
|
|
60
|
|
- assertFalse(palindromes.isEmpty());
|
|
|
39
|
+ final SortedMap<Long, List<List<Integer>>> palindromes = Palindromes.getPalindromeProductsWithFactors(10, 99);
|
|
61
|
40
|
|
|
62
|
|
- long actualValue = palindromes.lastKey();
|
|
63
|
|
- assertEquals(expectedValue, actualValue);
|
|
64
|
|
-
|
|
65
|
|
- List<List<Integer>> actual = palindromes
|
|
66
|
|
- .get(palindromes.lastKey())
|
|
67
|
|
- .stream()
|
|
68
|
|
- .sorted((a, b) -> Integer.compare(a.get(0), b.get(0)))
|
|
69
|
|
- .collect(Collectors.toList());
|
|
70
|
|
- assertEquals(expected, actual);
|
|
|
41
|
+ checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.lastKey());
|
|
71
|
42
|
}
|
|
72
|
43
|
|
|
73
|
44
|
@Test
|
|
|
@@ -80,24 +51,9 @@ public class PalindromesTest {
|
|
80
|
51
|
);
|
|
81
|
52
|
final long expectedValue = 121l;
|
|
82
|
53
|
|
|
83
|
|
- final SortedMap<Long, List<List<Integer>>> palindromes
|
|
84
|
|
- = Palindromes.getPalindromeSortedListBuilder()
|
|
85
|
|
- .withFactorsLessThanOrEqualTo(99)
|
|
86
|
|
- .withFactorsGreaterThanOrEqualTo(10)
|
|
87
|
|
- .build();
|
|
88
|
|
-
|
|
89
|
|
- assertNotNull(palindromes);
|
|
90
|
|
- assertFalse(palindromes.isEmpty());
|
|
|
54
|
+ final SortedMap<Long, List<List<Integer>>> palindromes = Palindromes.getPalindromeProductsWithFactors(10, 99);
|
|
91
|
55
|
|
|
92
|
|
- long actualValue = palindromes.firstKey();
|
|
93
|
|
- assertEquals(expectedValue, actualValue);
|
|
94
|
|
-
|
|
95
|
|
- List<List<Integer>> actual = palindromes
|
|
96
|
|
- .get(palindromes.firstKey())
|
|
97
|
|
- .stream()
|
|
98
|
|
- .sorted((a, b) -> Integer.compare(a.get(0), b.get(0)))
|
|
99
|
|
- .collect(Collectors.toList());
|
|
100
|
|
- assertEquals(expected, actual);
|
|
|
56
|
+ checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.firstKey());
|
|
101
|
57
|
}
|
|
102
|
58
|
|
|
103
|
59
|
@Test
|
|
|
@@ -110,24 +66,9 @@ public class PalindromesTest {
|
|
110
|
66
|
);
|
|
111
|
67
|
final long expectedValue = 906609l;
|
|
112
|
68
|
|
|
113
|
|
- final SortedMap<Long, List<List<Integer>>> palindromes
|
|
114
|
|
- = Palindromes.getPalindromeSortedListBuilder()
|
|
115
|
|
- .withFactorsLessThanOrEqualTo(999)
|
|
116
|
|
- .withFactorsGreaterThanOrEqualTo(100)
|
|
117
|
|
- .build();
|
|
118
|
|
-
|
|
119
|
|
- assertNotNull(palindromes);
|
|
120
|
|
- assertFalse(palindromes.isEmpty());
|
|
|
69
|
+ final SortedMap<Long, List<List<Integer>>> palindromes = Palindromes.getPalindromeProductsWithFactors(100, 999);
|
|
121
|
70
|
|
|
122
|
|
- long actualValue = palindromes.lastKey();
|
|
123
|
|
- assertEquals(expectedValue, actualValue);
|
|
124
|
|
-
|
|
125
|
|
- List<List<Integer>> actual = palindromes
|
|
126
|
|
- .get(palindromes.lastKey())
|
|
127
|
|
- .stream()
|
|
128
|
|
- .sorted((a, b) -> Integer.compare(a.get(0), b.get(0)))
|
|
129
|
|
- .collect(Collectors.toList());
|
|
130
|
|
- assertEquals(expected, actual);
|
|
|
71
|
+ checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.lastKey());
|
|
131
|
72
|
}
|
|
132
|
73
|
|
|
133
|
74
|
@Test
|
|
|
@@ -140,23 +81,25 @@ public class PalindromesTest {
|
|
140
|
81
|
);
|
|
141
|
82
|
final long expectedValue = 10201l;
|
|
142
|
83
|
|
|
143
|
|
- final SortedMap<Long, List<List<Integer>>> palindromes
|
|
144
|
|
- = Palindromes.getPalindromeSortedListBuilder()
|
|
145
|
|
- .withFactorsLessThanOrEqualTo(999)
|
|
146
|
|
- .withFactorsGreaterThanOrEqualTo(100)
|
|
147
|
|
- .build();
|
|
|
84
|
+ final SortedMap<Long, List<List<Integer>>> palindromes = Palindromes.getPalindromeProductsWithFactors(100, 999);
|
|
|
85
|
+
|
|
|
86
|
+ checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.firstKey());
|
|
|
87
|
+ }
|
|
148
|
88
|
|
|
149
|
|
- assertNotNull(palindromes);
|
|
150
|
|
- assertFalse(palindromes.isEmpty());
|
|
|
89
|
+ private void checkPalindromeWithFactorsMatchesExpected(List<List<Integer>> expectedPalindromeFactors,
|
|
|
90
|
+ long expectedValueOfPalindrome,
|
|
|
91
|
+ SortedMap<Long, List<List<Integer>>> actualPalindromes,
|
|
|
92
|
+ long actualValueOfPalindrome) {
|
|
|
93
|
+ assertNotNull(actualPalindromes);
|
|
|
94
|
+ assertFalse(actualPalindromes.isEmpty());
|
|
151
|
95
|
|
|
152
|
|
- long actualValue = palindromes.firstKey();
|
|
153
|
|
- assertEquals(expectedValue, actualValue);
|
|
|
96
|
+ assertEquals(expectedValueOfPalindrome, actualValueOfPalindrome);
|
|
154
|
97
|
|
|
155
|
|
- List<List<Integer>> actual = palindromes
|
|
156
|
|
- .get(palindromes.firstKey())
|
|
|
98
|
+ List<List<Integer>> actualPalindromeFactors = actualPalindromes
|
|
|
99
|
+ .get(actualValueOfPalindrome)
|
|
157
|
100
|
.stream()
|
|
158
|
101
|
.sorted((a, b) -> Integer.compare(a.get(0), b.get(0)))
|
|
159
|
102
|
.collect(Collectors.toList());
|
|
160
|
|
- assertEquals(expected, actual);
|
|
|
103
|
+ assertEquals(expectedPalindromeFactors, actualPalindromeFactors);
|
|
161
|
104
|
}
|
|
162
|
105
|
}
|