01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16:
17: package com.google.gwt.emultest.java.lang;
18:
19: import com.google.gwt.junit.client.GWTTestCase;
20:
21: /**
22: * Unit tests for the Javascript emulation of the Float/float autoboxed
23: * fundamental type.
24: */
25: public class FloatTest extends GWTTestCase {
26:
27: public String getModuleName() {
28: return "com.google.gwt.emultest.EmulSuite";
29: }
30:
31: public void testBadStrings() {
32: try {
33: new Float("0.0e");
34: fail("constructor");
35: } catch (NumberFormatException e) {
36: // Expected behavior
37: }
38:
39: try {
40: Float.parseFloat("0.0e");
41: fail("parse");
42: } catch (NumberFormatException e) {
43: // Expected behavior
44: }
45:
46: try {
47: Float.valueOf("0x0e");
48: fail("valueOf");
49: } catch (NumberFormatException e) {
50: // Expected behavior
51: }
52: }
53:
54: public void testFloatConstants() {
55: assertTrue(Float.isNaN(Float.NaN));
56: assertTrue(Float.isInfinite(Float.NEGATIVE_INFINITY));
57: assertTrue(Float.isInfinite(Float.POSITIVE_INFINITY));
58: assertTrue(Float.NEGATIVE_INFINITY < Float.POSITIVE_INFINITY);
59: assertTrue(Float.MIN_VALUE < Float.MAX_VALUE);
60: assertFalse(Float.NaN == Float.NaN);
61: assertEquals(Float.SIZE, 32);
62: // jdk1.6 assertEquals(Float.MIN_EXPONENT,
63: // Math.getExponent(Float.MIN_NORMAL));
64: // jdk1.6 assertEquals(Float.MAX_EXPONENT,
65: // Math.getExponent(Float.MAX_VALUE));
66: }
67:
68: public void testParse() {
69: assertTrue(0 == Float.parseFloat("0"));
70: assertTrue(-1.5 == Float.parseFloat("-1.5"));
71: assertTrue(3.0 == Float.parseFloat("3."));
72: assertTrue(0.5 == Float.parseFloat(".5"));
73: assertTrue("Can't parse MAX_VALUE", Float.MAX_VALUE == Float
74: .parseFloat(String.valueOf(Float.MAX_VALUE)));
75: assertTrue("Can't parse MIN_VALUE", Float.MIN_VALUE == Float
76: .parseFloat(String.valueOf(Float.MIN_VALUE)));
77: }
78: }
|