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: // J2SE dependencies and extensions
020: import java.util.Arrays;
021: import javax.units.SI;
022:
023: // JUnit dependencies
024: import junit.framework.Test;
025: import junit.framework.TestCase;
026: import junit.framework.TestSuite;
027:
028: // OpenGIS dependencies
029: import org.opengis.referencing.cs.AxisDirection;
030: import org.opengis.referencing.cs.CoordinateSystemAxis;
031:
032: /**
033: * Tests the {@link ComparableAxisWrapper} class.
034: *
035: * @version $Id: ComparableAxisWrapperTest.java 24683 2007-03-06 06:02:15Z desruisseaux $
036: * @author Martin Desruisseaux
037: */
038: public class ComparableAxisWrapperTest extends TestCase {
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(ComparableAxisWrapperTest.class);
051: }
052:
053: /**
054: * Constructs a test case with the given name.
055: */
056: public ComparableAxisWrapperTest(final String name) {
057: super (name);
058: }
059:
060: /**
061: * Tests sorting of axis.
062: */
063: public void testSortAxis() {
064: assertOrdered(
065: new CoordinateSystemAxis[] {
066: DefaultCoordinateSystemAxis.LONGITUDE,
067: DefaultCoordinateSystemAxis.LATITUDE,
068: DefaultCoordinateSystemAxis.ELLIPSOIDAL_HEIGHT },
069: new CoordinateSystemAxis[] {
070: DefaultCoordinateSystemAxis.LONGITUDE,
071: DefaultCoordinateSystemAxis.LATITUDE,
072: DefaultCoordinateSystemAxis.ELLIPSOIDAL_HEIGHT });
073: assertOrdered(
074: new CoordinateSystemAxis[] {
075: DefaultCoordinateSystemAxis.LATITUDE,
076: DefaultCoordinateSystemAxis.ELLIPSOIDAL_HEIGHT,
077: DefaultCoordinateSystemAxis.LONGITUDE },
078: new CoordinateSystemAxis[] {
079: DefaultCoordinateSystemAxis.LONGITUDE,
080: DefaultCoordinateSystemAxis.LATITUDE,
081: DefaultCoordinateSystemAxis.ELLIPSOIDAL_HEIGHT });
082: }
083:
084: /**
085: * Tests sorting of directions.
086: */
087: public void testSortDirections() {
088: // A plausible CS.
089: assertOrdered(new AxisDirection[] { AxisDirection.NORTH,
090: AxisDirection.UP, AxisDirection.EAST },
091: new AxisDirection[] { AxisDirection.EAST, // Right handed-rule
092: AxisDirection.NORTH, // Right handed-rule
093: AxisDirection.UP });
094:
095: // A very dummy CS just for testing. The order of
096: // any non-compass direction should be unchanged.
097: assertOrdered(new AxisDirection[] { AxisDirection.GEOCENTRIC_Y,
098: AxisDirection.NORTH_NORTH_WEST,
099: AxisDirection.GEOCENTRIC_X, AxisDirection.NORTH_EAST,
100: AxisDirection.PAST }, new AxisDirection[] {
101: AxisDirection.NORTH_EAST, // Right handed-rule
102: AxisDirection.NORTH_NORTH_WEST, // Right handed-rule
103: AxisDirection.GEOCENTRIC_Y, AxisDirection.GEOCENTRIC_X,
104: AxisDirection.PAST });
105:
106: // An other plausible CS.
107: assertOrdered(new AxisDirection[] { AxisDirection.SOUTH,
108: AxisDirection.DOWN, AxisDirection.WEST },
109: new AxisDirection[] { AxisDirection.WEST, // Right handed-rule
110: AxisDirection.SOUTH, // Right handed-rule
111: AxisDirection.DOWN });
112:
113: // An other plausible CS.
114: assertOrdered(new AxisDirection[] { AxisDirection.SOUTH,
115: AxisDirection.DOWN, AxisDirection.EAST },
116: new AxisDirection[] { AxisDirection.SOUTH, // Right handed-rule
117: AxisDirection.EAST, // Right handed-rule
118: AxisDirection.DOWN });
119: }
120:
121: /**
122: * Sorts the specified axis and compares against the expected result.
123: */
124: private static void assertOrdered(
125: final CoordinateSystemAxis[] toTest,
126: final CoordinateSystemAxis[] expected) {
127: final boolean same = Arrays.equals(toTest, expected);
128: assertEquals(!same, ComparableAxisWrapper.sort(toTest));
129: assertTrue(Arrays.equals(toTest, expected));
130: }
131:
132: /**
133: * Sorts the specified directions and compares against the expected result.
134: */
135: private static void assertOrdered(final AxisDirection[] toTest,
136: final AxisDirection[] expected) {
137: assertOrdered(toAxis(toTest), toAxis(expected));
138: }
139:
140: /**
141: * Creates axis from the specified directions.
142: */
143: private static CoordinateSystemAxis[] toAxis(
144: final AxisDirection[] directions) {
145: final CoordinateSystemAxis[] axis = new CoordinateSystemAxis[directions.length];
146: for (int i = 0; i < directions.length; i++) {
147: axis[i] = new DefaultCoordinateSystemAxis("Test",
148: directions[i], SI.METER);
149: }
150: return axis;
151: }
152: }
|