01: /*
02: * Copyright 2004, 2005, 2006 Odysseus Software GmbH
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of 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,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package de.odysseus.calyxo.forms.convert;
17:
18: import java.text.ParseException;
19:
20: import junit.framework.TestCase;
21:
22: /**
23: * DoubleConverter test case.
24: *
25: * @author Oliver Stuhr
26: */
27: public class DoubleConverterTest extends TestCase {
28: static final Double[] DOUBLES = new Double[] {
29: new Double(Double.NaN),
30: new Double(Double.NEGATIVE_INFINITY),
31: new Double(-Double.MAX_VALUE), new Double("-1"),
32: new Double(-Double.MIN_VALUE), new Double("0"),
33: new Double(Double.MIN_VALUE), new Double("1"),
34: new Double(Double.MAX_VALUE),
35: new Double(Double.POSITIVE_INFINITY) };
36:
37: /*
38: * Class under test for String format(Object) and Object parse(String)
39: */
40: public void test() {
41: DoubleConverter converter = new DoubleConverter();
42: converter.setMaximumFractionDigits(330); // default is 3, which doesn't work for Double.MIN_VALUE
43:
44: for (int i = 0; i < DOUBLES.length; i++)
45: try {
46: assertEquals(DOUBLES[i], converter.parse(converter
47: .format(DOUBLES[i])));
48: } catch (ParseException e) {
49: fail("-> ParseException: " + e);
50: }
51:
52: try {
53: assertEquals("0", converter.format(converter.parse(" 0")));
54: assertEquals("0", converter.format(converter.parse("0 ")));
55: assertEquals("0", converter.format(converter.parse("00")));
56: // assertEquals("0", converter.format(converter.parse("+0")));
57: assertEquals("-0", converter.format(converter.parse("-0")));
58: // assertEquals("0", converter.format(converter.parse("0.")));
59: assertEquals("0", converter.format(converter.parse(".0")));
60: // assertEquals("0", converter.format(converter.parse(".")));
61: // assertEquals("0", converter.format(converter.parse("+.")));
62: // assertEquals("0", converter.format(converter.parse("-.")));
63: } catch (ParseException e) {
64: fail("-> ParseException: " + e);
65: }
66: }
67: }
|