Skip to content

Commit ce4f8bb

Browse files
authored
Merge pull request exercism#1211 from FridaTveit/AllYourBaseUpdate
all-your-base: update tests to version 2.1.0
2 parents db59104 + 6ba177f commit ce4f8bb

3 files changed

Lines changed: 36 additions & 16 deletions

File tree

‎exercises/all-your-base/.meta/src/reference/java/BaseConverter.java‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ private void validateInputs(final int originalBase, final int[] originalDigits)
3939
}
4040

4141
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;
4743
}
4844

4945
if (Arrays.stream(originalDigits).min().getAsInt() < 0) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.0
1+
2.1.0

‎exercises/all-your-base/src/test/java/BaseConverterTest.java‎

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,18 @@ public void test15BitInteger() {
150150
@Ignore("Remove to run test")
151151
@Test
152152
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);
155157

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);
157165
}
158166

159167
@Ignore("Remove to run test")
@@ -176,19 +184,35 @@ public void testSingleZero() {
176184
@Ignore("Remove to run test")
177185
@Test
178186
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);
181191

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);
183199
}
184200

185201
@Ignore("Remove to run test")
186202
@Test
187203
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);
190208

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);
192216
}
193217

194218
@Ignore("Remove to run test")
@@ -250,7 +274,7 @@ public void testSecondBaseIsOne() {
250274
@Ignore("Remove to run test")
251275
@Test
252276
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});
254278

255279
expectedException.expect(IllegalArgumentException.class);
256280
expectedException.expectMessage("Bases must be at least 2.");

0 commit comments

Comments
 (0)