jpountz commented on code in PR #12453:
URL: https://github.com/apache/lucene/pull/12453#discussion_r1271956372
##########
lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java:
##########
@@ -209,6 +209,103 @@ public void testBackwardsLongReads() throws IOException {
"Expected 4 or 3, got " + input.readCount, input.readCount == 4 ||
input.readCount == 3);
}
+ public void testReadFloats() throws IOException {
+ final int length = 1024 * 8;
+ MyBufferedIndexInput input = new MyBufferedIndexInput(length);
+ ByteBuffer bb =
ByteBuffer.allocate(Float.BYTES).order(ByteOrder.LITTLE_ENDIAN);
+ final int bufferLength = 128;
+ float[] floatBuffer = new float[bufferLength];
+
+ for (int alignment = 0; alignment < Float.BYTES; alignment++) {
+ input.seek(0);
+ for (int i = 0; i < alignment; i++) {
+ input.readByte();
+ }
+ final int bulkReads = length / (bufferLength * Float.BYTES) - 1;
+ for (int i = 0; i < bulkReads; i++) {
+ int pos = alignment + i * bufferLength * Float.BYTES;
+ final int floatOffset = random().nextInt(3);
+ input.skipBytes(floatOffset * Float.BYTES);
+ input.readFloats(floatBuffer, floatOffset, bufferLength - floatOffset);
+ for (int idx = floatOffset; idx < bufferLength; idx++) {
+ final int offset = pos + idx * Float.BYTES;
+ bb.position(0)
+ .put(byten(offset))
+ .put(byten(offset + 1))
+ .put(byten(offset + 2))
+ .put(byten(offset + 3));
+ assertEquals(bb.getFloat(0), floatBuffer[idx], 0f);
Review Comment:
nit: would it make more sense to compare the int bits rather than the float
itself, to make sure +/-0 or the different representations of NaN are
considered different?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]