Kaynağa Gözat

Merge pull request #1211 from FridaTveit/AllYourBaseUpdate

all-your-base: update tests to version 2.1.0
Sam Warner 8 yıl önce
ebeveyn
işleme
ce4f8bbdbb
No account linked to committer's email

+ 1
- 5
exercises/all-your-base/.meta/src/reference/java/BaseConverter.java Dosyayı Görüntüle

39
         }
39
         }
40
 
40
 
41
         if (originalDigits.length == 0) {
41
         if (originalDigits.length == 0) {
42
-            throw new IllegalArgumentException("You must supply at least one digit.");
43
-        }
44
-
45
-        if (originalDigits.length > 1 && originalDigits[0] == 0) {
46
-            throw new IllegalArgumentException("Digits may not contain leading zeros.");
42
+            return;
47
         }
43
         }
48
 
44
 
49
         if (Arrays.stream(originalDigits).min().getAsInt() < 0) {
45
         if (Arrays.stream(originalDigits).min().getAsInt() < 0) {

+ 1
- 1
exercises/all-your-base/.meta/version Dosyayı Görüntüle

1
-1.1.0
1
+2.1.0

+ 34
- 10
exercises/all-your-base/src/test/java/BaseConverterTest.java Dosyayı Görüntüle

150
     @Ignore("Remove to run test")
150
     @Ignore("Remove to run test")
151
     @Test
151
     @Test
152
     public void testEmptyDigits() {
152
     public void testEmptyDigits() {
153
-        expectedException.expect(IllegalArgumentException.class);
154
-        expectedException.expectMessage("You must supply at least one digit.");
153
+        final BaseConverter baseConverter = new BaseConverter(2, new int[]{});
154
+
155
+        final int[] expectedDigits = new int[]{0};
156
+        final int[] actualDigits = baseConverter.convertToBase(10);
155
 
157
 
156
-        new BaseConverter(2, new int[]{});
158
+        assertArrayEquals(
159
+            String.format(
160
+                "Expected digits: %s but found digits: %s",
161
+                Arrays.toString(expectedDigits),
162
+                Arrays.toString(actualDigits)),
163
+            expectedDigits,
164
+            actualDigits);
157
     }
165
     }
158
 
166
 
159
     @Ignore("Remove to run test")
167
     @Ignore("Remove to run test")
176
     @Ignore("Remove to run test")
184
     @Ignore("Remove to run test")
177
     @Test
185
     @Test
178
     public void testMultipleZeros() {
186
     public void testMultipleZeros() {
179
-        expectedException.expect(IllegalArgumentException.class);
180
-        expectedException.expectMessage("Digits may not contain leading zeros.");
187
+        final BaseConverter baseConverter = new BaseConverter(10, new int[]{0, 0, 0});
188
+
189
+        final int[] expectedDigits = new int[]{0};
190
+        final int[] actualDigits = baseConverter.convertToBase(2);
181
 
191
 
182
-        new BaseConverter(10, new int[]{0, 0, 0});
192
+        assertArrayEquals(
193
+            String.format(
194
+                "Expected digits: %s but found digits: %s",
195
+                Arrays.toString(expectedDigits),
196
+                Arrays.toString(actualDigits)),
197
+            expectedDigits,
198
+            actualDigits);
183
     }
199
     }
184
 
200
 
185
     @Ignore("Remove to run test")
201
     @Ignore("Remove to run test")
186
     @Test
202
     @Test
187
     public void testLeadingZeros() {
203
     public void testLeadingZeros() {
188
-        expectedException.expect(IllegalArgumentException.class);
189
-        expectedException.expectMessage("Digits may not contain leading zeros.");
204
+        final BaseConverter baseConverter = new BaseConverter(7, new int[]{0, 6, 0});
205
+
206
+        final int[] expectedDigits = new int[]{4, 2};
207
+        final int[] actualDigits = baseConverter.convertToBase(10);
190
 
208
 
191
-        new BaseConverter(7, new int[]{0, 6, 0});
209
+        assertArrayEquals(
210
+            String.format(
211
+                "Expected digits: %s but found digits: %s",
212
+                Arrays.toString(expectedDigits),
213
+                Arrays.toString(actualDigits)),
214
+            expectedDigits,
215
+            actualDigits);
192
     }
216
     }
193
 
217
 
194
     @Ignore("Remove to run test")
218
     @Ignore("Remove to run test")
250
     @Ignore("Remove to run test")
274
     @Ignore("Remove to run test")
251
     @Test
275
     @Test
252
     public void testSecondBaseIsZero() {
276
     public void testSecondBaseIsZero() {
253
-        final BaseConverter baseConverter = new BaseConverter(2, new int[]{1, 0, 1, 0, 1, 0});
277
+        final BaseConverter baseConverter = new BaseConverter(10, new int[]{7});
254
 
278
 
255
         expectedException.expect(IllegalArgumentException.class);
279
         expectedException.expect(IllegalArgumentException.class);
256
         expectedException.expectMessage("Bases must be at least 2.");
280
         expectedException.expectMessage("Bases must be at least 2.");