Pārlūkot izejas kodu

update palindrome-products

Jeffrey Sander 8 gadus atpakaļ
vecāks
revīzija
d35a09db04

+ 6
- 2
exercises/palindrome-products/.meta/src/reference/java/PalindromeCalculator.java Parādīt failu

@@ -3,7 +3,9 @@ import java.util.*;
3 3
 public class PalindromeCalculator {
4 4
 
5 5
     public SortedMap<Long, List<List<Integer>>> getPalindromeProductsWithFactors(int minFactor, int maxFactor) {
6
-    	if(minFactor > maxFactor) throw new IllegalArgumentException("invalid input: min is " + minFactor + " and max is " + maxFactor);
6
+    	if(minFactor > maxFactor) {
7
+    		throw new IllegalArgumentException("invalid input: min is " + minFactor + " and max is " + maxFactor);
8
+    	}
7 9
     	
8 10
         SortedMap<Long, List<List<Integer>>> palindromeSortedList = new TreeMap<>();
9 11
         long num;
@@ -22,7 +24,9 @@ public class PalindromeCalculator {
22 24
             }
23 25
         }
24 26
         
25
-        if(palindromeSortedList.size() == 0) throw new NoSuchElementException("no palindrome with factors in the range " + minFactor + " to " + maxFactor);
27
+        if(palindromeSortedList.size() == 0) {
28
+    		throw new NoSuchElementException("no palindrome with factors in the range " + minFactor + " to " + maxFactor);
29
+    	}
26 30
         
27 31
         return Collections.unmodifiableSortedMap(palindromeSortedList);
28 32
     }

+ 28
- 28
exercises/palindrome-products/src/test/java/PalindromeCalculatorTest.java Parādīt failu

@@ -30,14 +30,14 @@ public class PalindromeCalculatorTest {
30 30
     
31 31
     @Test
32 32
     public void smallestPalindromeFromSingleDigitFactors() {
33
-        final List<List<Integer>> expected = Collections.unmodifiableList(
33
+        List<List<Integer>> expected = Collections.unmodifiableList(
34 34
                 Arrays.asList(
35 35
                         Arrays.asList(1, 1)
36 36
                 )
37 37
         );
38
-        final long expectedValue = 1l;
38
+        long expectedValue = 1l;
39 39
 
40
-        final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(1, 9);
40
+        SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(1, 9);
41 41
 
42 42
         checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.firstKey());
43 43
     }
@@ -45,15 +45,15 @@ public class PalindromeCalculatorTest {
45 45
     @Ignore("Remove to run test")
46 46
     @Test
47 47
     public void largestPalindromeFromSingleDigitFactors() {
48
-        final List<List<Integer>> expected = Collections.unmodifiableList(
48
+        List<List<Integer>> expected = Collections.unmodifiableList(
49 49
                 Arrays.asList(
50 50
                         Arrays.asList(1, 9),
51 51
                         Arrays.asList(3, 3)
52 52
                 )
53 53
         );
54
-        final long expectedValue = 9l;
54
+        long expectedValue = 9l;
55 55
 
56
-        final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(1, 9);
56
+        SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(1, 9);
57 57
 
58 58
         checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.lastKey());
59 59
     }
@@ -61,14 +61,14 @@ public class PalindromeCalculatorTest {
61 61
     @Ignore("Remove to run test")
62 62
     @Test
63 63
     public void largestPalindromeFromDoubleDigitFactors() {
64
-        final List<List<Integer>> expected = Collections.unmodifiableList(
64
+        List<List<Integer>> expected = Collections.unmodifiableList(
65 65
                 Arrays.asList(
66 66
                         Arrays.asList(91, 99)
67 67
                 )
68 68
         );
69
-        final long expectedValue = 9009l;
69
+        long expectedValue = 9009l;
70 70
 
71
-        final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(10, 99);
71
+        SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(10, 99);
72 72
 
73 73
         checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.lastKey());
74 74
     }
@@ -76,14 +76,14 @@ public class PalindromeCalculatorTest {
76 76
     @Ignore("Remove to run test")
77 77
     @Test
78 78
     public void smallestPalindromeFromDoubleDigitFactors() {
79
-        final List<List<Integer>> expected = Collections.unmodifiableList(
79
+        List<List<Integer>> expected = Collections.unmodifiableList(
80 80
                 Arrays.asList(
81 81
                         Arrays.asList(11, 11)
82 82
                 )
83 83
         );
84
-        final long expectedValue = 121l;
84
+        long expectedValue = 121l;
85 85
 
86
-        final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(10, 99);
86
+        SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(10, 99);
87 87
 
88 88
         checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.firstKey());
89 89
     }
@@ -91,14 +91,14 @@ public class PalindromeCalculatorTest {
91 91
     @Ignore("Remove to run test")
92 92
     @Test
93 93
     public void largestPalindromeFromTripleDigitFactors() {
94
-        final List<List<Integer>> expected = Collections.unmodifiableList(
94
+        List<List<Integer>> expected = Collections.unmodifiableList(
95 95
                 Arrays.asList(
96 96
                         Arrays.asList(913, 993)
97 97
                 )
98 98
         );
99
-        final long expectedValue = 906609l;
99
+        long expectedValue = 906609l;
100 100
 
101
-        final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(100, 999);
101
+        SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(100, 999);
102 102
 
103 103
         checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.lastKey());
104 104
     }
@@ -106,14 +106,14 @@ public class PalindromeCalculatorTest {
106 106
     @Ignore("Remove to run test")
107 107
     @Test
108 108
     public void smallestPalindromeFromTripleDigitFactors() {
109
-        final List<List<Integer>> expected = Collections.unmodifiableList(
109
+        List<List<Integer>> expected = Collections.unmodifiableList(
110 110
                 Arrays.asList(
111 111
                         Arrays.asList(101, 101)
112 112
                 )
113 113
         );
114
-        final long expectedValue = 10201l;
114
+        long expectedValue = 10201l;
115 115
 
116
-        final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(100, 999);
116
+        SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(100, 999);
117 117
 
118 118
         checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.firstKey());
119 119
     }
@@ -121,14 +121,14 @@ public class PalindromeCalculatorTest {
121 121
     @Ignore("Remove to run test")
122 122
     @Test
123 123
     public void smallestPalindromeFromQuadDigitFactors() {
124
-        final List<List<Integer>> expected = Collections.unmodifiableList(
124
+        List<List<Integer>> expected = Collections.unmodifiableList(
125 125
                 Arrays.asList(
126 126
                         Arrays.asList(1001, 1001)
127 127
                 )
128 128
         );
129
-        final long expectedValue = 1002001l;
129
+        long expectedValue = 1002001l;
130 130
 
131
-        final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(1000, 9999);
131
+        SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(1000, 9999);
132 132
 
133 133
         checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.firstKey());
134 134
     }
@@ -136,14 +136,14 @@ public class PalindromeCalculatorTest {
136 136
     @Ignore("Remove to run test")
137 137
     @Test
138 138
     public void largestPalindromeFromQuadDigitFactors() {
139
-        final List<List<Integer>> expected = Collections.unmodifiableList(
139
+        List<List<Integer>> expected = Collections.unmodifiableList(
140 140
                 Arrays.asList(
141 141
                         Arrays.asList(9901, 9999)
142 142
                 )
143 143
         );
144
-        final long expectedValue = 99000099l;
144
+        long expectedValue = 99000099l;
145 145
 
146
-        final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(1000, 9999);
146
+        SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(1000, 9999);
147 147
 
148 148
         checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.lastKey());
149 149
     }
@@ -155,7 +155,7 @@ public class PalindromeCalculatorTest {
155 155
         expectedException.expect(NoSuchElementException.class);
156 156
         expectedException.expectMessage("no palindrome with factors in the range 1002 to 1003");
157 157
 
158
-        final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(1002, 1003);
158
+        SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(1002, 1003);
159 159
     }
160 160
     
161 161
     @Ignore("Remove to run test")
@@ -165,7 +165,7 @@ public class PalindromeCalculatorTest {
165 165
         expectedException.expect(NoSuchElementException.class);
166 166
         expectedException.expectMessage("no palindrome with factors in the range 15 to 15");
167 167
 
168
-        final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(15, 15);
168
+        SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(15, 15);
169 169
     }
170 170
     
171 171
     @Ignore("Remove to run test")
@@ -175,7 +175,7 @@ public class PalindromeCalculatorTest {
175 175
         expectedException.expect(IllegalArgumentException.class);
176 176
         expectedException.expectMessage("invalid input: min is 10000 and max is 1");
177 177
 
178
-        final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(10000, 1);
178
+        SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(10000, 1);
179 179
     }
180 180
     
181 181
     @Ignore("Remove to run test")
@@ -185,7 +185,7 @@ public class PalindromeCalculatorTest {
185 185
         expectedException.expect(IllegalArgumentException.class);
186 186
         expectedException.expectMessage("invalid input: min is 2 and max is 1");
187 187
 
188
-        final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(2, 1);
188
+        SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(2, 1);
189 189
     }
190 190
     
191 191