001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2007, GeoTools Project Managment Committee (PMC)
005: * (C) 2007, Geomatys
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation;
010: * version 2.1 of the License.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.referencing.cs;
018:
019: // JUnit dependencies
020: import junit.framework.Test;
021: import junit.framework.TestCase;
022: import junit.framework.TestSuite;
023:
024: // OpenGIS dependencies
025: import org.opengis.referencing.cs.AxisDirection;
026:
027: /**
028: * Tests the {@link DirectionAlongMeridian} class.
029: *
030: * @version $Id: DirectionAlongMeridianTest.java 24683 2007-03-06 06:02:15Z desruisseaux $
031: * @author Martin Desruisseaux
032: */
033: public class DirectionAlongMeridianTest extends TestCase {
034: /**
035: * For floating point comparaisons.
036: */
037: private static final double EPS = 1E-10;
038:
039: /**
040: * Run the suite from the command line.
041: */
042: public static void main(final String[] args) {
043: junit.textui.TestRunner.run(suite());
044: }
045:
046: /**
047: * Returns the test suite.
048: */
049: public static Test suite() {
050: return new TestSuite(DirectionAlongMeridianTest.class);
051: }
052:
053: /**
054: * Constructs a test case with the given name.
055: */
056: public DirectionAlongMeridianTest(final String name) {
057: super (name);
058: }
059:
060: /**
061: * Tests the {@link DirectionAlongMeridian#parse} method.
062: */
063: public void testParse() {
064: DirectionAlongMeridian dir;
065: String name;
066:
067: name = "South along 180 deg";
068: dir = DirectionAlongMeridian.parse(name);
069: assertNotNull(dir);
070: assertEquals(AxisDirection.SOUTH, dir.baseDirection);
071: assertEquals(180, dir.meridian, 0);
072: assertEquals(name, dir.toString());
073:
074: name = "South along 90 deg East";
075: dir = DirectionAlongMeridian.parse(name);
076: assertNotNull(dir);
077: assertEquals(AxisDirection.SOUTH, dir.baseDirection);
078: assertEquals(90, dir.meridian, 0);
079: assertEquals(name, dir.toString());
080:
081: name = "South along 90 deg West";
082: dir = DirectionAlongMeridian.parse(name);
083: assertNotNull(dir);
084: assertEquals(AxisDirection.SOUTH, dir.baseDirection);
085: assertEquals(-90, dir.meridian, 0);
086: assertEquals(name, dir.toString());
087:
088: name = "North along 45 deg East";
089: dir = DirectionAlongMeridian.parse(name);
090: assertNotNull(dir);
091: assertEquals(AxisDirection.NORTH, dir.baseDirection);
092: assertEquals(45, dir.meridian, 0);
093: assertEquals(name, dir.toString());
094: }
095:
096: /**
097: * Tests the ordering, which also involve a test of angle measurement.
098: */
099: public void testOrdering() {
100: assertOrdered("North along 90 deg East", "North along 0 deg");
101: assertOrdered("North along 75 deg West",
102: "North along 165 deg West");
103: assertOrdered("South along 90 deg West", "South along 0 deg");
104: assertOrdered("South along 180 deg", "South along 90 deg West");
105: assertOrdered("North along 130 deg West",
106: "North along 140 deg East");
107: }
108:
109: /**
110: * Tests if the following directions have an angle of 90° between each other.
111: */
112: private static void assertOrdered(final String dir1,
113: final String dir2) {
114: final DirectionAlongMeridian m1 = DirectionAlongMeridian
115: .parse(dir1);
116: final DirectionAlongMeridian m2 = DirectionAlongMeridian
117: .parse(dir2);
118: assertEquals(+90, m1.getAngle(m2), EPS);
119: assertEquals(-90, m2.getAngle(m1), EPS);
120: assertEquals(-1, m1.compareTo(m2));
121: assertEquals(+1, m2.compareTo(m1));
122: assertFalse(m1.equals(m2));
123: }
124: }
|