aherbert commented on code in PR #877:
URL: https://github.com/apache/commons-lang/pull/877#discussion_r883054287
##########
src/test/java/org/apache/commons/lang3/ConversionTest.java:
##########
@@ -413,6 +415,29 @@ public void testBinaryBeMsb0ToHexDigit_2args() {
}
+ @Test
+ public void testBinaryToHexDigitReverse() {
+ final SplittableRandom rng = new SplittableRandom();
+ final boolean[] x = new boolean[8];
+ for (int i = 0; i < 100; i++) {
+ Conversion.longToBinary(rng.nextLong(), 0, x, 0, 8);
+ for (int j = 1; j <= 8; j++) {
+ final boolean[] a = Arrays.copyOf(x, j);
+ final boolean[] b = a.clone();
+ ArrayUtils.reverse(b);
+ for (int k = 0; k < j; k++) {
+ assertEquals(Conversion.binaryToHexDigit(a, k),
+ Conversion.binaryBeMsb0ToHexDigit(b, k));
+ }
+ }
+ }
+ }
+
+ @Test
+ public void binaryBeMsb0ToHexDigitPosOutsideArray() {
+ assertThrows(IndexOutOfBoundsException.class, () ->
Conversion.binaryBeMsb0ToHexDigit(new boolean[8], 99));
Review Comment:
I would have just added to the existing test:
```Java
@Test
public void binaryBeMsb0ToHexDigitPosOutsideArray() {
final boolean[] array = new boolean[8];
for (final int index : new int[] {-1, array.length, array.length + 100})
{
assertThrows(IndexOutOfBoundsException.class,
() -> Conversion.binaryBeMsb0ToHexDigit(array, index),
() -> "Index: " + index;
);
}
}
```
Or perhaps use a parameterized test:
```Java
@ParameterizedTest
@ValueSource(ints = {-1, 8, 99})
public void binaryBeMsb0ToHexDigitPosOutsideArray(int index) {
assertThrows(IndexOutOfBoundsException.class,
() -> Conversion.binaryBeMsb0ToHexDigit(new boolean[8], index));
}
```
Anyway can you rebase this on master and then it is good to merge. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]