You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2022/05/26 16:18:59 UTC

[GitHub] [commons-lang] arturobernalg commented on a diff in pull request #877: Simplify and remove unnecessary check.

arturobernalg commented on code in PR #877:
URL: https://github.com/apache/commons-lang/pull/877#discussion_r882849172


##########
src/main/java/org/apache/commons/lang3/Conversion.java:
##########
@@ -435,39 +435,40 @@ public static char binaryBeMsb0ToHexDigit(final boolean[] src) {
      * @return a hexadecimal digit representing the selected bits
      * @throws IllegalArgumentException if {@code src} is empty
      * @throws NullPointerException if {@code src} is {@code null}
+     * @throws IndexOutOfBoundsException if {@code srcPos} is outside the array.
      */
     public static char binaryBeMsb0ToHexDigit(boolean[] src, int srcPos) {
         if (src.length == 0) {

Review Comment:
   done



##########
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:
   done



-- 
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: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org