jfboeuf commented on code in PR #13989: URL: https://github.com/apache/lucene/pull/13989#discussion_r1855164834
########## lucene/core/src/test/org/apache/lucene/store/TestBufferedChecksum.java: ########## @@ -63,4 +67,127 @@ public void testRandom() { } assertEquals(c1.getValue(), c2.getValue()); } + + public void testDifferentInputTypes() { + Checksum crc = new CRC32(); + BufferedChecksum buffered = new BufferedChecksum(new CRC32()); + int iterations = atLeast(1000); + for (int i = 0; i < iterations; i++) { + byte[] input = new byte[4096]; + random().nextBytes(input); + crc.update(input); + final long checksum = crc.getValue(); + crc.reset(); + updateByShorts(checksum, buffered, input); + updateByInts(checksum, buffered, input); + updateByLongs(checksum, buffered, input); + updateByChunkOfBytes(checksum, buffered, input); + updateByChunkOfLongs(checksum, buffered, input); + } + } + + private void updateByChunkOfBytes(long expected, BufferedChecksum checksum, byte[] input) { + for (int i = 0; i < input.length; i++) { + checksum.update(input[i]); + } + checkChecksumValueAndReset(expected, checksum); + + checksum.update(input); + checkChecksumValueAndReset(expected, checksum); + + int iterations = atLeast(10); + for (int ite = 0; ite < iterations; ite++) { + int len0 = random().nextInt(input.length / 2); + checksum.update(input, 0, len0); + checksum.update(input, len0, input.length - len0); + checkChecksumValueAndReset(expected, checksum); + + checksum.update(input, 0, len0); + int len1 = random().nextInt(input.length / 4); + for (int i = 0; i < len1; i++) { + checksum.update(input[len0 + i]); + } + checksum.update(input, len0 + len1, input.length - len1 - len0); + checkChecksumValueAndReset(expected, checksum); + } + } + + private void updateByShorts(long expected, BufferedChecksum checksum, byte[] input) { + int ix = shiftArray(checksum, input); + while (ix < input.length - Short.BYTES) { Review Comment: we can indeed do one more loop! 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-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org