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: * FloatConverter test case.
24: *
25: * @author Oliver Stuhr
26: */
27: public class FloatConverterTest extends TestCase {
28: static final Float[] FLOATS = new Float[] { new Float(Float.NaN),
29: new Float(Float.NEGATIVE_INFINITY),
30: new Float(-Float.MAX_VALUE), new Float("-1"),
31: new Float(-Float.MIN_VALUE), new Float("0"),
32: new Float(Float.MIN_VALUE), new Float("1"),
33: new Float(Float.MAX_VALUE),
34: new Float(Float.POSITIVE_INFINITY) };
35:
36: /*
37: * Class under test for String format(Object) and Object parse(String)
38: */
39: public void test() {
40: FloatConverter converter = new FloatConverter();
41: converter.setMaximumFractionDigits(50); // default is 3, which doesn't work for Float.MIN_VALUE
42:
43: for (int i = 0; i < FLOATS.length; i++)
44: try {
45: assertEquals(FLOATS[i], converter.parse(converter
46: .format(FLOATS[i])));
47: } catch (ParseException e) {
48: fail("-> ParseException: " + e);
49: }
50:
51: try {
52: assertEquals("0", converter.format(converter.parse(" 0")));
53: assertEquals("0", converter.format(converter.parse("0 ")));
54: assertEquals("0", converter.format(converter.parse("00")));
55: // assertEquals("0", converter.format(converter.parse("+0")));
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(".")));
60: // assertEquals("0", converter.format(converter.parse("+.")));
61: // assertEquals("0", converter.format(converter.parse("-.")));
62: } catch (ParseException e) {
63: fail("-> ParseException: " + e);
64: }
65: }
66: }
|