01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2004-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; either
09: * version 2.1 of the License, or (at your option) any later version.
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.resources;
17:
18: // JUnit dependencies
19: import junit.framework.Test;
20: import junit.framework.TestCase;
21: import junit.framework.TestSuite;
22:
23: /**
24: * Tests the {@link XMath} static methods.
25: *
26: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/test/java/org/geotools/resources/XMathTest.java $
27: * @version $Id: XMathTest.java 24576 2007-02-24 00:07:40Z desruisseaux $
28: * @author Martin Desruisseaux
29: */
30: public final class XMathTest extends TestCase {
31: /**
32: * Run the test from the command line.
33: */
34: public static void main(String[] args) {
35: junit.textui.TestRunner.run(suite());
36: }
37:
38: /**
39: * Returns the test suite.
40: */
41: public static Test suite() {
42: return new TestSuite(XMathTest.class);
43: }
44:
45: /**
46: * Constructs a test case with the given name.
47: */
48: public XMathTest(String name) {
49: super (name);
50: }
51:
52: /**
53: * Tests the {@link XMath#pow10} method.
54: */
55: public void testPow10() {
56: for (int i = -304; i <= 304; i++) {
57: assertEquals(Double.parseDouble("1E" + i), XMath.pow10(i),
58: 0);
59: }
60: }
61:
62: /**
63: * Tests the {@link XMath#countFractionDigits} method.
64: */
65: public void testCountFractionDigits() {
66: assertEquals(0, XMath.countFractionDigits(-65.0));
67: assertEquals(1, XMath.countFractionDigits(-65.5));
68: assertEquals(6, XMath.countFractionDigits(65.123456));
69: assertEquals(0, XMath.countFractionDigits(1.23456E+200));
70: assertEquals(1, XMath.countFractionDigits(5E-1));
71: assertEquals(5, XMath.countFractionDigits(5E-5));
72: assertEquals(10, XMath.countFractionDigits(5E-10));
73: assertEquals(200, XMath.countFractionDigits(5E-200));
74: assertEquals(203, XMath.countFractionDigits(5.125E-200));
75: }
76:
77: /**
78: * Tests the {@link XMath#fixRoundingError} method.
79: */
80: public void testFixRoundingError() {
81: assertEquals(-61.5, XMath.fixRoundingError(-61.50000000000001,
82: 12), 0);
83: assertEquals(-61.5, XMath.fixRoundingError(-61.50000000000001,
84: 13), 0);
85: assertEquals(-61.50000000000001, XMath.fixRoundingError(
86: -61.50000000000001, 14), 0);
87: assertEquals(-61.50000010000001, XMath.fixRoundingError(
88: -61.50000010000001, 10), 0);
89: assertEquals(-61.5, XMath.fixRoundingError(-61.50000000000000,
90: 15), 0);
91: }
92: }
|