1818
1919import com .google .gwt .junit .client .GWTTestCase ;
2020
21+ import static java .lang .Float .NaN ;
22+
2123/**
2224 * Unit tests for the Javascript emulation of the Float/float autoboxed
2325 * fundamental type.
@@ -57,45 +59,45 @@ public void testCompare() {
5759 assertTrue ("Float.compare failed for 2 > 1" , Float .compare (2f , 1f ) > 0 );
5860 assertEquals (0 , Float .compare (1f , 1f ));
5961
60- assertEquals (0 , Float .compare (Float . NaN , Float . NaN ));
61- assertTrue (Float .compare (0.0f , Float . NaN ) < 0 );
62- assertTrue (Float .compare (Float . NaN , Float .POSITIVE_INFINITY ) > 0 );
63- assertTrue (Float .compare (Float . NaN , 0.0f ) > 0 );
64- assertTrue (Float .compare (Float .POSITIVE_INFINITY , Float . NaN ) < 0 );
62+ assertEquals (0 , Float .compare (NaN , NaN ));
63+ assertTrue (Float .compare (0.0f , NaN ) < 0 );
64+ assertTrue (Float .compare (NaN , Float .POSITIVE_INFINITY ) > 0 );
65+ assertTrue (Float .compare (NaN , 0.0f ) > 0 );
66+ assertTrue (Float .compare (Float .POSITIVE_INFINITY , NaN ) < 0 );
6567 }
6668
6769 @ SuppressWarnings ("SelfComparison" )
6870 public void testCompareTo () {
6971 Float float1 = new Float (1f );
7072 Float float2 = new Float (2f );
71- Float floatNaN1 = new Float (Float . NaN );
73+ Float floatNaN1 = new Float (NaN );
7274
7375 assertTrue ("Float.compare failed for 1 < 2" , float1 .compareTo (2f ) < 0 );
7476 assertTrue ("Float.compare failed for 2 > 1" , float2 .compareTo (1f ) > 0 );
7577 assertEquals (0 , float1 .compareTo (float1 ));
7678
77- assertEquals (0 , floatNaN1 .compareTo (new Float (Float . NaN )));
78- assertTrue (new Float (0.0f ).compareTo (new Float (Float . NaN )) < 0 );
79+ assertEquals (0 , floatNaN1 .compareTo (new Float (NaN )));
80+ assertTrue (new Float (0.0f ).compareTo (new Float (NaN )) < 0 );
7981 assertTrue (floatNaN1 .compareTo (new Float (Float .POSITIVE_INFINITY )) > 0 );
8082 assertTrue (floatNaN1 .compareTo (new Float (0.0f )) > 0 );
81- assertTrue (new Float (Float .POSITIVE_INFINITY ).compareTo (new Float (Float . NaN )) < 0 );
83+ assertTrue (new Float (Float .POSITIVE_INFINITY ).compareTo (new Float (NaN )) < 0 );
8284 }
8385
8486 @ SuppressWarnings ({"SelfEquality" , "EqualsNaN" })
8587 public void testFloatConstants () {
86- assertTrue (Float .isNaN (Float . NaN ));
88+ assertTrue (Float .isNaN (NaN ));
8789 assertTrue (Float .isInfinite (Float .NEGATIVE_INFINITY ));
8890 assertTrue (Float .isInfinite (Float .POSITIVE_INFINITY ));
8991 assertTrue (Float .NEGATIVE_INFINITY < Float .POSITIVE_INFINITY );
9092 assertTrue (Float .MIN_VALUE < Float .MAX_VALUE );
91- assertFalse (Float . NaN == Float . NaN );
93+ assertFalse (NaN == NaN );
9294 assertEquals (Float .SIZE , 32 );
9395 // jdk1.6 assertEquals(Float.MIN_EXPONENT,
9496 // Math.getExponent(Float.MIN_NORMAL));
9597 // jdk1.6 assertEquals(Float.MAX_EXPONENT,
9698 // Math.getExponent(Float.MAX_VALUE));
9799 // issue 8073 - used to fail in prod mode
98- assertFalse (Float .isInfinite (Float . NaN ));
100+ assertFalse (Float .isInfinite (NaN ));
99101 }
100102
101103 public void testParse () {
@@ -162,6 +164,22 @@ public void testParse() {
162164 }
163165 }
164166
167+ public void testToHexString () {
168+ assertEquals ("-0x1.0p0" , Float .toHexString (-1.0f ));
169+ assertEquals ("0x1.0p0" , Float .toHexString (1.0f ));
170+ assertEquals ("0x1.0p1" , Float .toHexString (2.0f ));
171+ assertEquals ("0x1.8p1" , Float .toHexString (3.0f ));
172+ assertEquals ("0x1.5p5" , Float .toHexString (42.0f ));
173+ assertEquals ("0x1.81c8p13" , Float .toHexString (12345.0f ));
174+ assertEquals ("0x0.0p0" , Float .toHexString (0.0f ));
175+ assertEquals ("-0x0.0p0" , Float .toHexString (-0.0f ));
176+ assertEquals ("Infinity" , Float .toHexString (Float .POSITIVE_INFINITY ));
177+ assertEquals ("-Infinity" , Float .toHexString (-Float .NEGATIVE_INFINITY ));
178+ assertEquals ("NaN" , Float .toHexString (NaN ));
179+ assertEquals ("0x1.0p-126" , Float .toHexString (Float .MIN_NORMAL ));
180+ assertEquals ("0x0.8p-126" , Float .toHexString (Float .MIN_NORMAL / 2 ));
181+ }
182+
165183 public void testFloatBits () {
166184 compareFloatBits (0x1 , 1.401298464324817E-45F );
167185 compareFloatBits (0x2 , 1.401298464324817E-45F * 2.0F );
@@ -187,7 +205,7 @@ public void testFloatBits() {
187205 compareFloatBits (0x0 , 0.0F );
188206 compareFloatBits (0x80000000 , -0.0F );
189207 compareFloatBits (0x80000000 , 1.0F / Float .NEGATIVE_INFINITY );
190- compareFloatBits (0x7fc00000 , Float . NaN );
208+ compareFloatBits (0x7fc00000 , NaN );
191209 compareFloatBits (0x7f800000 , Float .POSITIVE_INFINITY );
192210 compareFloatBits (0xff800000 , Float .NEGATIVE_INFINITY );
193211 compareFloatBits (0x3f800000 , 1.0F );
0 commit comments