01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.xs.bindings;
17:
18: import javax.xml.namespace.QName;
19:
20: import org.geotools.xs.TestSchema;
21:
22: public class XSFloatStrategyTest extends TestSchema {
23: public void validateValues(String given, Float expected)
24: throws Exception {
25: Float actual = (Float) strategy.parse(element(given, qname),
26: given);
27: assertEquals(given, expected, actual);
28: }
29:
30: /**
31: * For example, -1E4, 1267.43233E12, 12.78e-2, 12 , -0, 0 and INF are all
32: * legal literals for float.
33: * @throws Exception
34: */
35: public void testWhiteSpace() throws Exception {
36: validateValues(" \n12", new Float(12));
37: }
38:
39: public void testParse() throws Exception {
40: validateValues("-1E4", new Float(-1E4));
41: validateValues("1267.43233E12", new Float(1267.43233E12));
42: validateValues("12.78e-2", new Float(12.78e-2));
43: validateValues("12", new Float(12));
44: validateValues("-0", new Float("-0"));
45: validateValues("0", new Float(0));
46: validateValues("INF", new Float(Float.POSITIVE_INFINITY));
47: }
48:
49: protected QName getQName() {
50: return XS.FLOAT;
51: }
52: }
|