You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2011/02/23 22:42:43 UTC
svn commit: r1073957 -
/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestSmallFloat.java
Author: yonik
Date: Wed Feb 23 21:42:42 2011
New Revision: 1073957
URL: http://svn.apache.org/viewvc?rev=1073957&view=rev
Log:
tests: add a few more floatToByte constant tests
Modified:
lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestSmallFloat.java
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestSmallFloat.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestSmallFloat.java?rev=1073957&r1=1073956&r2=1073957&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestSmallFloat.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestSmallFloat.java Wed Feb 23 21:42:42 2011
@@ -81,12 +81,6 @@ public class TestSmallFloat extends Luce
public void testByteToFloat() {
- assertEquals(0, orig_floatToByte_v13(5.8123817E-10f)); // verify the old bug (see LUCENE-2937)
- assertEquals(1, orig_floatToByte(5.8123817E-10f)); // verify it's fixed in this test code
- assertEquals(1, SmallFloat.floatToByte315(5.8123817E-10f)); // verify it's fixed
-
- assertEquals(1, orig_floatToByte(Float.MIN_VALUE));
-
for (int i=0; i<256; i++) {
float f1 = orig_byteToFloat((byte)i);
float f2 = SmallFloat.byteToFloat((byte)i, 3,15);
@@ -101,6 +95,22 @@ public class TestSmallFloat extends Luce
}
public void testFloatToByte() {
+ assertEquals(0, orig_floatToByte_v13(5.8123817E-10f)); // verify the old bug (see LUCENE-2937)
+ assertEquals(1, orig_floatToByte(5.8123817E-10f)); // verify it's fixed in this test code
+ assertEquals(1, SmallFloat.floatToByte315(5.8123817E-10f)); // verify it's fixed
+
+ // test some constants
+ assertEquals(0, SmallFloat.floatToByte315(0));
+ assertEquals(1, SmallFloat.floatToByte315(Float.MIN_VALUE)); // underflow rounds up to smallest positive
+ assertEquals(255, SmallFloat.floatToByte315(Float.MAX_VALUE) & 0xff); // overflow rounds down to largest positive
+ assertEquals(255, SmallFloat.floatToByte315(Float.POSITIVE_INFINITY) & 0xff);
+
+ // all negatives map to 0
+ assertEquals(0, SmallFloat.floatToByte315(-Float.MIN_VALUE));
+ assertEquals(0, SmallFloat.floatToByte315(-Float.MAX_VALUE));
+ assertEquals(0, SmallFloat.floatToByte315(Float.NEGATIVE_INFINITY));
+
+
// up iterations for more exhaustive test after changing something
int num = 100000 * RANDOM_MULTIPLIER;
for (int i = 0; i < num; i++) {