This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-codec.git
commit 486d8a8ae45e9d9e0e44ffb6048e536491c59c1a Author: aherbert <aherb...@apache.org> AuthorDate: Thu Nov 21 15:54:10 2019 +0000 MurmurHash3: Added random block sizes to incremental hash test. --- .../commons/codec/digest/MurmurHash3Test.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java b/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java index 79787f3..0443fe2 100644 --- a/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java +++ b/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java @@ -747,6 +747,10 @@ public class MurmurHash3Test { assertIncrementalHash32(bytes, seed, 4, 3); // Complete blocks assertIncrementalHash32(bytes, seed, 4, 16, 64); + // Some random blocks + for (int i = 0; i < 10; i++) { + assertIncrementalHash32x86(bytes, seed, createRandomBlocks(bytes.length)); + } } } @@ -801,6 +805,10 @@ public class MurmurHash3Test { assertIncrementalHash32x86(bytes, seed, 4, 3); // Complete blocks assertIncrementalHash32x86(bytes, seed, 4, 16, 64); + // Some random blocks + for (int i = 0; i < 10; i++) { + assertIncrementalHash32x86(bytes, seed, createRandomBlocks(bytes.length)); + } } } @@ -829,4 +837,23 @@ public class MurmurHash3Test { Assert.assertEquals("Hashes differ after no additional data", h1, inc.end()); } } + + /** + * Creates the random blocks of data to process up to max length. + * + * @param maxLength the max length + * @return the blocks + */ + private static int[] createRandomBlocks(int maxLength) { + int[] blocks = new int[20]; + int count = 0; + int length = 0; + while (count < blocks.length && length < maxLength) { + // range of 1 to 8 for up to two 4 byte blocks + final int size = ThreadLocalRandom.current().nextInt(1, 9); + blocks[count++] = size; + length += size; + } + return Arrays.copyOf(blocks, count); + } }