sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1546496 - in /sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis: referencing/cs/CommonAxes.java referencing/cs/CoordinateSystemsTest.java referencing/cs/DefaultCartesianCSTest.java test/suite/ReferencingTestSuite.java
Date Fri, 29 Nov 2013 03:20:16 GMT
Author: desruisseaux
Date: Fri Nov 29 03:20:15 2013
New Revision: 1546496

URL: http://svn.apache.org/r1546496
Log:
Added tests.

Added:
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/DefaultCartesianCSTest.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CommonAxes.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CoordinateSystemsTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CommonAxes.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CommonAxes.java?rev=1546496&r1=1546495&r2=1546496&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CommonAxes.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CommonAxes.java
[UTF-8] Fri Nov 29 03:20:15 2013
@@ -130,6 +130,12 @@ public final strictfp class CommonAxes {
             AxisDirection.UP, Double.POSITIVE_INFINITY, SI.METRE);
 
     /**
+     * A height in centimetres, for {@link CoordinateSystemsTest} only.
+     */
+    static final DefaultCoordinateSystemAxis HEIGHT_cm = create("Height", "h",
+            AxisDirection.UP, Double.POSITIVE_INFINITY, SI.CENTIMETRE);
+
+    /**
      * The default axis for altitude values.
      * Increasing ordinates values go {@linkplain AxisDirection#UP up} and units are {@linkplain
SI#METRE metres}.
      * The abbreviation is lower case "<var>h</var>".
@@ -364,6 +370,18 @@ public final strictfp class CommonAxes {
             AxisDirection.SOUTH, Double.POSITIVE_INFINITY, SI.METRE);
 
     /**
+     * An axis with North-East orientation.
+     */
+    static final DefaultCoordinateSystemAxis NORTH_EAST = create("NORTH_EAST", "NE",
+            AxisDirection.NORTH_EAST, Double.POSITIVE_INFINITY, SI.METRE);
+
+    /**
+     * An axis with South-East orientation.
+     */
+    static final DefaultCoordinateSystemAxis SOUTH_EAST = create("SOUTH_EAST", "SE",
+            AxisDirection.SOUTH_EAST, Double.POSITIVE_INFINITY, SI.METRE);
+
+    /**
      * A default axis for time values in a {@linkplain org.opengis.referencing.cs.TimeCS
time CS}.
      * Increasing time go toward {@linkplain AxisDirection#FUTURE future} and units are {@linkplain
NonSI#DAY days}.
      * The abbreviation is lower case "<var>t</var>".

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CoordinateSystemsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CoordinateSystemsTest.java?rev=1546496&r1=1546495&r2=1546496&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CoordinateSystemsTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CoordinateSystemsTest.java
[UTF-8] Fri Nov 29 03:20:15 2013
@@ -16,7 +16,11 @@
  */
 package org.apache.sis.referencing.cs;
 
+import javax.measure.converter.ConversionException;
+import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.cs.AxisDirection;
+import org.opengis.referencing.cs.CoordinateSystem;
+import org.apache.sis.referencing.operation.matrix.Matrices;
 import org.apache.sis.internal.referencing.AxisDirections;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
@@ -24,8 +28,10 @@ import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static java.lang.StrictMath.*;
-import static org.junit.Assert.*;
+import static java.util.Collections.singletonMap;
+import static org.opengis.referencing.IdentifiedObject.NAME_KEY;
 import static org.apache.sis.referencing.cs.CoordinateSystems.*;
+import static org.apache.sis.test.Assert.*;
 
 
 /**
@@ -154,4 +160,88 @@ public final strictfp class CoordinateSy
         assertNotNull(target, dir2);
         assertEquals(expected, angle(dir1, dir2), STRICT);
     }
+
+    /**
+     * Tests {@link CoordinateSystems#swapAndScaleAxes(CoordinateSystem, CoordinateSystem)}
for (λ,φ) ↔ (φ,λ).
+     * This very common conversion is of critical importance to Apache SIS.
+     *
+     * @throws ConversionException Should not happen.
+     */
+    @Test
+    public void testSwapAndScaleAxes2D() throws ConversionException {
+        final CoordinateSystem λφ = new DefaultEllipsoidalCS(singletonMap(NAME_KEY, "(λ,φ)"),
+                CommonAxes.GEODETIC_LONGITUDE,
+                CommonAxes.GEODETIC_LATITUDE);
+        final CoordinateSystem φλ = new DefaultEllipsoidalCS(singletonMap(NAME_KEY, "(φ,λ)"),
+                CommonAxes.GEODETIC_LATITUDE,
+                CommonAxes.GEODETIC_LONGITUDE);
+        final Matrix expected = Matrices.create(3, 3, new double[] {
+                0, 1, 0,
+                1, 0, 0,
+                0, 0, 1});
+        assertTrue(swapAndScaleAxes(λφ, λφ).isIdentity());
+        assertTrue(swapAndScaleAxes(φλ, φλ).isIdentity());
+        assertMatrixEquals("(λ,φ) → (φ,λ)", expected, swapAndScaleAxes(λφ, φλ),
STRICT);
+        assertMatrixEquals("(φ,λ) → (λ,φ)", expected, swapAndScaleAxes(φλ, λφ),
STRICT);
+    }
+
+    /**
+     * Tests {@link CoordinateSystems#swapAndScaleAxes(CoordinateSystem, CoordinateSystem)}
for (λ,φ,h) ↔ (φ,λ,h).
+     * This very common conversion is of critical importance to Apache SIS.
+     *
+     * @throws ConversionException Should not happen.
+     */
+    @Test
+    @DependsOnMethod("testSwapAndScaleAxes2D")
+    public void testSwapAndScaleAxes3D() throws ConversionException {
+        final CoordinateSystem λφh = new DefaultEllipsoidalCS(singletonMap(NAME_KEY, "(λ,φ,h)"),
+                CommonAxes.GEODETIC_LONGITUDE,
+                CommonAxes.GEODETIC_LATITUDE,
+                CommonAxes.ELLIPSOIDAL_HEIGHT);
+        final CoordinateSystem φλh = new DefaultEllipsoidalCS(singletonMap(NAME_KEY, "(φ,λ,h)"),
+                CommonAxes.GEODETIC_LATITUDE,
+                CommonAxes.GEODETIC_LONGITUDE,
+                CommonAxes.ELLIPSOIDAL_HEIGHT);
+        final Matrix expected = Matrices.create(4, 4, new double[] {
+                0, 1, 0, 0,
+                1, 0, 0, 0,
+                0, 0, 1, 0,
+                0, 0, 0, 1});
+        assertTrue(swapAndScaleAxes(λφh, λφh).isIdentity());
+        assertTrue(swapAndScaleAxes(φλh, φλh).isIdentity());
+        assertMatrixEquals("(λ,φ,h) → (φ,λ,h)", expected, swapAndScaleAxes(λφh, φλh),
STRICT);
+        assertMatrixEquals("(φ,λ,h) → (λ,φ,h)", expected, swapAndScaleAxes(φλh, λφh),
STRICT);
+    }
+
+    /**
+     * Tests {@link CoordinateSystems#swapAndScaleAxes(CoordinateSystem, CoordinateSystem)}
+     * with a more arbitrary case, which include unit conversions.
+     *
+     * @throws ConversionException Should not happen.
+     */
+    @Test
+    @DependsOnMethod("testSwapAndScaleAxes3D")
+    public void testSwapAndScaleAxes() throws ConversionException {
+        final CoordinateSystem hxy = new DefaultCartesianCS(singletonMap(NAME_KEY, "(h,x,y)"),
+                CommonAxes.HEIGHT_cm,
+                CommonAxes.EASTING,
+                CommonAxes.NORTHING);
+        final CoordinateSystem yxh = new DefaultCartesianCS(singletonMap(NAME_KEY, "(y,x,h)"),
+                CommonAxes.SOUTHING,
+                CommonAxes.EASTING,
+                CommonAxes.DEPTH);
+        assertTrue(swapAndScaleAxes(hxy, hxy).isIdentity());
+        assertTrue(swapAndScaleAxes(yxh, yxh).isIdentity());
+        assertMatrixEquals("(h,x,y) → (y,x,h)", Matrices.create(4, 4, new double[] {
+                0,    0,   -1,    0,
+                0,    1,    0,    0,
+               -0.01, 0,    0,    0,
+                0,    0,    0,    1}), swapAndScaleAxes(hxy, yxh), STRICT);
+
+        assertMatrixEquals("(y,x,h) → (h,x,y)", Matrices.create(4, 4, new double[] {
+                0,    0, -100,    0,
+                0,    1,    0,    0,
+               -1,    0,    0,    0,
+                0,    0,    0,    1}), swapAndScaleAxes(yxh, hxy), STRICT);
+    }
 }

Added: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/DefaultCartesianCSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/DefaultCartesianCSTest.java?rev=1546496&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/DefaultCartesianCSTest.java
(added)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/DefaultCartesianCSTest.java
[UTF-8] Fri Nov 29 03:20:15 2013
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.referencing.cs;
+
+import java.util.Map;
+import org.opengis.test.Validators;
+import org.apache.sis.test.TestCase;
+import org.apache.sis.test.DependsOn;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+import static java.util.Collections.singletonMap;
+
+
+/**
+ * Tests the {@link DefaultCartesianCS} class.
+ *
+ * @author  Martin Desruisseaux (IRD)
+ * @since   0.4 (derived from geotk-2.2)
+ * @version 0.4
+ * @module
+ */
+@DependsOn(DefaultCoordinateSystemAxisTest.class)
+public final strictfp class DefaultCartesianCSTest extends TestCase {
+    /**
+     * Tests the creation of a Cartesian CS with legal axes.
+     */
+    @Test
+    public void testConstructor() {
+        final Map<String,?> properties = singletonMap(DefaultCartesianCS.NAME_KEY,
"Test");
+        DefaultCartesianCS cs;
+        /*
+         * (E,N) : legal axes for the usual projected CRS.
+         */
+        cs = new DefaultCartesianCS(properties,
+                CommonAxes.EASTING,
+                CommonAxes.NORTHING);
+        Validators.validate(cs);
+        /*
+         * (NE,SE) : same CS rotated by 45°
+         */
+        cs = new DefaultCartesianCS(properties,
+                CommonAxes.NORTH_EAST,
+                CommonAxes.SOUTH_EAST);
+        Validators.validate(cs);
+        /*
+         * (NE,h) : considered perpendicular.
+         */
+        cs = new DefaultCartesianCS(properties,
+                CommonAxes.NORTH_EAST,
+                CommonAxes.ALTITUDE);
+        Validators.validate(cs);
+    }
+
+    /**
+     * Tests the creation of a Cartesian CS with illegal axes.
+     */
+    @Test
+    public void testConstructorArgumentChecks() {
+        final Map<String,?> properties = singletonMap(DefaultCartesianCS.NAME_KEY,
"Test");
+        /*
+         * (λ,φ) : illegal units.
+         */
+        try {
+            final DefaultCartesianCS cs = new DefaultCartesianCS(properties,
+                    CommonAxes.LONGITUDE,
+                    CommonAxes.LATITUDE);
+            fail("Angular units should not be accepted for " + cs);
+        } catch (IllegalArgumentException e) {
+            assertFalse(e.getMessage().isEmpty());
+        }
+        /*
+         * (S,N) : co-linear axes.
+         */
+        try {
+            final DefaultCartesianCS cs = new DefaultCartesianCS(properties,
+                    CommonAxes.SOUTHING,
+                    CommonAxes.NORTHING);
+            fail("Colinear units should not be accepted for " + cs);
+        } catch (IllegalArgumentException e) {
+            assertFalse(e.getMessage().isEmpty());
+        }
+        try {
+            final DefaultCartesianCS cs = new DefaultCartesianCS(properties,
+                    CommonAxes.NORTH_EAST,
+                    CommonAxes.EASTING);
+            fail("Non-perpendicular axis should not be accepted for " + cs);
+        } catch (IllegalArgumentException e) {
+            assertFalse(e.getMessage().isEmpty());
+        }
+    }
+}

Propchange: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/DefaultCartesianCSTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/DefaultCartesianCSTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1546496&r1=1546495&r2=1546496&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Fri Nov 29 03:20:15 2013
@@ -59,6 +59,7 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.datum.DefaultGeodeticDatumTest.class,
     org.apache.sis.referencing.cs.DirectionAlongMeridianTest.class,
     org.apache.sis.referencing.cs.DefaultCoordinateSystemAxisTest.class,
+    org.apache.sis.referencing.cs.DefaultCartesianCSTest.class,
     org.apache.sis.referencing.cs.CoordinateSystemsTest.class,
     org.apache.sis.referencing.StandardDefinitionsTest.class,
     org.apache.sis.referencing.GeodeticObjectsTest.class,



Mime
View raw message