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 emulated-in-Javascript Double/double autoboxed types.
23: */
24: public class DoubleTest extends GWTTestCase {
25:
26: public String getModuleName() {
27: return "com.google.gwt.emultest.EmulSuite";
28: }
29:
30: public void testBadStrings() {
31: try {
32: new Double("0.0e");
33: fail("constructor");
34: } catch (NumberFormatException e) {
35: // Expected behavior
36: }
37:
38: try {
39: Double.parseDouble("0.0e");
40: fail("parse");
41: } catch (NumberFormatException e) {
42: // Expected behavior
43: }
44:
45: try {
46: Double.valueOf("0x0e");
47: fail("valueOf");
48: } catch (NumberFormatException e) {
49: // Expected behavior
50: }
51: }
52:
53: public void testDoubleConstants() {
54: assertTrue(Double.isNaN(Double.NaN));
55: assertTrue(Double.isInfinite(Double.NEGATIVE_INFINITY));
56: assertTrue(Double.isInfinite(Double.POSITIVE_INFINITY));
57: assertTrue(Double.NEGATIVE_INFINITY < Double.POSITIVE_INFINITY);
58: assertTrue(Double.MIN_VALUE < Double.MAX_VALUE);
59: assertFalse(Double.NaN == Double.NaN);
60: assertEquals(64, Double.SIZE);
61: // jdk1.6 assertEquals(Math.getExponent(Double.MAX_VALUE),
62: // Double.MAX_EXPONENT);
63: // jdk1.6 assertEquals(Math.getExponent(Double.MIN_NORMAL),
64: // Double.MIN_EXPONENT);
65: }
66:
67: public void testParse() {
68: assertTrue(0 == Double.parseDouble("0"));
69: assertTrue(-1.5 == Double.parseDouble("-1.5"));
70: assertTrue(3.0 == Double.parseDouble("3."));
71: assertTrue(0.5 == Double.parseDouble(".5"));
72: assertTrue(2.98e8 == Double.parseDouble("2.98e8"));
73: assertTrue(-2.98e-8 == Double.parseDouble("-2.98e-8"));
74: assertTrue(+2.98E+8 == Double.parseDouble("+2.98E+8"));
75: assertTrue("Can't parse MIN_VALUE", Double.MIN_VALUE == Double
76: .parseDouble(String.valueOf(Double.MIN_VALUE)));
77: assertTrue("Can't parse MAX_VALUE", Double.MAX_VALUE == Double
78: .parseDouble(String.valueOf(Double.MAX_VALUE)));
79: }
80: }
|