sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1600886 - in /sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis: referencing/operation/transform/ test/suite/
Date Fri, 06 Jun 2014 13:48:01 GMT
Author: desruisseaux
Date: Fri Jun  6 13:48:00 2014
New Revision: 1600886

URL: http://svn.apache.org/r1600886
Log:
Ported ProjectiveTransformTest.

Added:
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformFactoryBase.java
  (with props)
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CopyTransformTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformTestCase.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CopyTransformTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CopyTransformTest.java?rev=1600886&r1=1600885&r2=1600886&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CopyTransformTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/CopyTransformTest.java
[UTF-8] Fri Jun  6 13:48:00 2014
@@ -21,8 +21,6 @@ import org.apache.sis.referencing.operat
 import org.apache.sis.test.DependsOn;
 import org.junit.Test;
 
-import static org.junit.Assert.*;
-
 
 /**
  * Tests the {@link CopyTransform} class.
@@ -32,7 +30,7 @@ import static org.junit.Assert.*;
  * @version 0.5
  * @module
  */
-//@DependsOn(ProjectiveTransformTest.class)
+@DependsOn(ProjectiveTransformTest.class)
 public final strictfp class CopyTransformTest extends MathTransformTestCase {
     /**
      * Generates random ordinates with approximatively 5% of NaN values in the array.
@@ -58,17 +56,14 @@ public final strictfp class CopyTransfor
         transform = new CopyTransform(3, 0, 1, 2);
         validate();
         verifyParameters(Affine.PARAMETERS, null);
-        assertTrue(((LinearTransform) transform).getMatrix().isIdentity());
-        assertTrue(transform.isIdentity());
+        verifyIsIdentity(true);
 
         final double[] source = generateRandomCoordinates();
         final double[] target = source.clone();
         verifyTransform(source, target);
-        stress(source);
 
         makeProjectiveTransform();
         verifyTransform(source, target);
-        stress(source);
     }
 
     /**
@@ -80,8 +75,7 @@ public final strictfp class CopyTransfor
     public void test3D() throws TransformException {
         transform = new CopyTransform(3, 2, 1, 0);
         validate();
-        assertFalse(transform.isIdentity());
-        assertFalse(((LinearTransform) transform).getMatrix().isIdentity());
+        verifyIsIdentity(false);
 
         final double[] source = generateRandomCoordinates();
         final double[] target = new double[source.length];
@@ -91,11 +85,9 @@ public final strictfp class CopyTransfor
             target[b + (2-r)] = source[i];
         }
         verifyTransform(source, target);
-        stress(source);
 
         makeProjectiveTransform();
         verifyTransform(source, target);
-        stress(source);
     }
 
     /**
@@ -108,8 +100,7 @@ public final strictfp class CopyTransfor
         transform = new CopyTransform(3, 0, 1);
         isInverseTransformSupported = false;
         validate();
-        assertFalse(transform.isIdentity());
-        assertFalse(((LinearTransform) transform).getMatrix().isIdentity());
+        verifyIsIdentity(false);
 
         final double[] source = generateRandomCoordinates();
         final double[] target = new double[source.length * 2/3];
@@ -119,10 +110,8 @@ public final strictfp class CopyTransfor
             // Skip one i (in the for loop).
         }
         verifyTransform(source, target);
-        stress(source);
 
         makeProjectiveTransform();
         verifyTransform(source, target);
-        stress(source);
     }
 }

Added: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformFactoryBase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformFactoryBase.java?rev=1600886&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformFactoryBase.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformFactoryBase.java
[UTF-8] Fri Jun  6 13:48:00 2014
@@ -0,0 +1,121 @@
+/*
+ * 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.operation.transform;
+
+import java.util.Set;
+import java.util.Collections;
+import org.opengis.util.FactoryException;
+import org.opengis.util.NoSuchIdentifierException;
+import org.opengis.metadata.citation.Citation;
+import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.referencing.cs.CoordinateSystem;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.operation.Matrix;
+import org.opengis.referencing.operation.OperationMethod;
+import org.opengis.referencing.operation.SingleOperation;
+import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.MathTransformFactory;
+import org.apache.sis.metadata.iso.citation.HardCodedCitations;
+
+
+/**
+ * Skeleton for {@link MathTransformFactory} custom implementations.
+ * Implementors need to override at least one method.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5 (derived from geotk-3.19)
+ * @version 0.5
+ * @module
+ */
+strictfp class MathTransformFactoryBase implements MathTransformFactory {
+    /**
+     * The message for all exception.
+     */
+    private static final String MESSAGE = "Undefined by the test suite.";
+
+    /**
+     * For subclasses constructor only.
+     */
+    protected MathTransformFactoryBase() {
+    }
+
+    /** Returns the Apache SIS citation. */
+    @Override
+    public Citation getVendor() {
+        return HardCodedCitations.SIS;
+    }
+
+    /** Default implementation returns an empty set. */
+    @Override
+    public Set<OperationMethod> getAvailableMethods(Class<? extends SingleOperation>
type) {
+        return Collections.emptySet();
+    }
+
+    /** Default implementation unconditionally returns {@code null}. */
+    @Override
+    public OperationMethod getLastMethodUsed() {
+        return null;
+    }
+
+    /** Default implementation throws an exception. */
+    @Override
+    public ParameterValueGroup getDefaultParameters(String method) throws NoSuchIdentifierException
{
+        throw new NoSuchIdentifierException(MESSAGE, method);
+    }
+
+    /** Default implementation throws an exception. */
+    @Override
+    public MathTransform createBaseToDerived(CoordinateReferenceSystem baseCRS, ParameterValueGroup
parameters, CoordinateSystem derivedCS) throws FactoryException {
+        throw new FactoryException(MESSAGE);
+    }
+
+    /** Default implementation throws an exception. */
+    @Override
+    public MathTransform createParameterizedTransform(ParameterValueGroup parameters) throws
FactoryException {
+        throw new FactoryException(MESSAGE);
+    }
+
+    /** Default implementation throws an exception. */
+    @Override
+    public MathTransform createAffineTransform(Matrix matrix) throws FactoryException {
+        throw new FactoryException(MESSAGE);
+    }
+
+    /** Default implementation throws an exception. */
+    @Override
+    public MathTransform createConcatenatedTransform(MathTransform transform1, MathTransform
transform2) throws FactoryException {
+        throw new FactoryException(MESSAGE);
+    }
+
+    /** Default implementation throws an exception. */
+    @Override
+    public MathTransform createPassThroughTransform(int firstAffectedOrdinate, MathTransform
subTransform, int numTrailingOrdinates) throws FactoryException {
+        throw new FactoryException(MESSAGE);
+    }
+
+    /** Default implementation throws an exception. */
+    @Override
+    public MathTransform createFromXML(String xml) throws FactoryException {
+        throw new FactoryException(MESSAGE);
+    }
+
+    /** Default implementation throws an exception. */
+    @Override
+    public MathTransform createFromWKT(String wkt) throws FactoryException {
+        throw new FactoryException(MESSAGE);
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformFactoryBase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformFactoryBase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformTestCase.java?rev=1600886&r1=1600885&r2=1600886&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformTestCase.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformTestCase.java
[UTF-8] Fri Jun  6 13:48:00 2014
@@ -19,6 +19,7 @@ package org.apache.sis.referencing.opera
 import java.util.Random;
 import java.io.IOException;
 import java.io.PrintStream;
+import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransform1D;
 import org.opengis.referencing.operation.MathTransform2D;
@@ -37,13 +38,13 @@ import org.apache.sis.util.Classes;
 import org.apache.sis.io.TableAppender;
 import org.apache.sis.io.wkt.Convention;
 import org.apache.sis.io.wkt.FormattableObject;
+import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.math.Statistics;
 import org.apache.sis.math.StatisticsFormat;
 import org.apache.sis.test.TestUtilities;
 import org.apache.sis.test.TestCase;
 
 import static java.lang.StrictMath.*;
-import static org.apache.sis.util.Classes.*;
 import static org.apache.sis.test.ReferencingAssert.*;
 
 
@@ -232,14 +233,30 @@ public abstract strictfp class MathTrans
     }
 
     /**
-     * Transforms the given coordinates and verifies that the result is equals (within a
positive
-     * delta) to the expected ones. If the difference between an expected and actual ordinate
value
-     * is greater than the {@linkplain #tolerance tolerance} threshold, then the assertion
fails.
+     * Verifies if {@link MathTransform#isIdentity()} on the current {@linkplain #transform
transform}.
+     * If the current transform is linear, then this method will also verifies {@link Matrix#isIdentity()}.
+     *
+     * @param expected The expected return value of {@code isIdentit()} methods.
+     */
+    protected final void verifyIsIdentity(final boolean expected) {
+        assertEquals(completeMessage("isIdentity()"), expected, transform.isIdentity());
+        if (transform instanceof LinearTransform) {
+            assertEquals(completeMessage("getMatrix().isIdentity()"), expected,
+                    ((LinearTransform) transform).getMatrix().isIdentity());
+        }
+    }
+
+    /**
+     * Transforms the given coordinates and verifies that the result is equals (within a
positive delta)
+     * to the expected ones. If the difference between an expected and actual ordinate value
is greater
+     * than the {@linkplain #tolerance tolerance} threshold, then the assertion fails.
      *
      * <p>If {@link #isInverseTransformSupported} is {@code true}, then this method
will also transform
      * the expected coordinate points using the {@linkplain MathTransform#inverse() inverse
transform} and
      * compare with the source coordinates.</p>
      *
+     * <p>This method verifies also the consistency of {@code MathTransform.transform(…)}
method variants.</p>
+     *
      * @param  coordinates The coordinate points to transform.
      * @param  expected The expect result of the transformation, or
      *         {@code null} if {@code coordinates} is expected to be null.
@@ -249,24 +266,35 @@ public abstract strictfp class MathTrans
     protected final void verifyTransform(final double[] coordinates, final double[] expected)
throws TransformException {
         super.verifyTransform(coordinates, expected);
         /*
-         * In addition to the GeoAPI "verifyTransform" check, check also for consistency.
-         * A previous version of Geotk had a bug with the Google projection which was
-         * unnoticed because of lack of this consistency check.
+         * In addition to the GeoAPI "verifyTransform" check, check also for consistency
of various variant
+         * of MathTransform.transform(…) methods.  In GeoAPI, 'verifyTransform' and 'verifyConsistency'
are
+         * two independent steps because not all developers may want to perform both verifications
together.
+         * But in Apache SIS, we want to verify consistency for all math transform. A previous
Geotk version
+         * had a bug with the Google projection which was unnoticed because of lack of this
consistency check.
          */
-        final float[] copy = new float[coordinates.length];
-        for (int i=0; i<copy.length; i++) {
-            copy[i] = (float) coordinates[i];
+        final float[] asFloats = Numerics.copyAsFloats(coordinates);
+        final float[] result   = verifyConsistency(asFloats);
+        final String  message  = completeMessage("Detected change in source coordinates.");
+        for (int i=0; i<coordinates.length; i++) {
+            assertEquals(message, (float) coordinates[i], asFloats[i], 0f); // Paranoiac
check.
         }
-        final float[] result = verifyConsistency(copy);
         /*
          * The comparison below needs a higher tolerance threshold, because we converted
the source
          * ordinates to floating points which induce a lost of precision. The multiplication
factor
          * used here has been determined empirically. The value is quite high, but this is
only an
          * oportunist check anyway. The "real" test is the one performed by 'verifyConsistency'.
+         * We do not perform this check for non-linear transforms, because the difference
in input
+         * have too unpredictable consequences on the output.
          */
-        final double tol = max(tolerance * 1000, 1);
-        for (int i=0; i<expected.length; i++) {
-            assertEquals(expected[i], result[i], tol);
+        if (transform instanceof LinearTransform) {
+            for (int i=0; i<expected.length; i++) {
+                final double e = expected[i];
+                double tol = 1E-6 * abs(e);
+                if (!(tol > tolerance)) {   // Use '!' for replacing NaN by 'tolerance'.
+                    tol = tolerance;
+                }
+                assertEquals(e, result[i], tol);
+            }
         }
     }
 
@@ -311,33 +339,6 @@ public abstract strictfp class MathTrans
     }
 
     /**
-     * Stress the current {@linkplain #transform transform} using the given coordinates.
-     * This method do not {@linkplain #validate() validate} the transform.
-     * This is caller's responsibility to do so if applicable.
-     *
-     * @param  source The input coordinates to use for testing.
-     * @throws TransformException If at transformation failed.
-     */
-    final void stress(final double[] source) throws TransformException {
-        final float[] asFloats = new float[source.length];
-        for (int i=0; i<source.length; i++) {
-            asFloats[i] = (float) source[i];
-        }
-        if (isInverseTransformSupported) {
-            verifyInverse(source);
-        }
-        for (int i=0; i<source.length; i++) {
-            assertEquals(completeMessage("Detected change in source coordinates."),
-                    asFloats[i], (float) source[i], 0f); // Paranoiac check.
-        }
-        verifyConsistency(asFloats);
-        for (int i=0; i<source.length; i++) {
-            assertEquals(completeMessage("Detected change in source coordinates."),
-                    (float) source[i], asFloats[i], 0f); // Paranoiac check.
-        }
-    }
-
-    /**
      * Asserts that the current {@linkplain #transform transform} produces the given WKT.
      *
      * @param expected The expected WKT.

Added: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java?rev=1600886&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
[UTF-8] Fri Jun  6 13:48:00 2014
@@ -0,0 +1,59 @@
+/*
+ * 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.operation.transform;
+
+import org.opengis.referencing.operation.Matrix;
+import org.opengis.test.referencing.AffineTransformTest;
+import org.apache.sis.test.DependsOn;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+
+/**
+ * Tests the {@link ProjectiveTransform} class by inheriting the tests defined in GeoAPI
conformance module.
+ * We use the {@link AffineTransform2D} class as a reference, so we need to avoid NaN values.
+ * Note that {@link CopyTransformTest} will use {@code ProjectiveTransform} as a reference,
+ * this time with NaN values.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5 (derived from geotk-3.08)
+ * @version 0.5
+ * @module
+ */
+@RunWith(JUnit4.class)
+@DependsOn(AbstractMathTransformTest.class)
+public final strictfp class ProjectiveTransformTest extends AffineTransformTest {
+    /**
+     * Creates a new test suite.
+     */
+    public ProjectiveTransformTest() {
+        super(new MathTransformFactoryBase() {
+            @Override
+            public ProjectiveTransform createAffineTransform(final Matrix matrix) {
+                if (matrix.getNumRow() == 3 && matrix.getNumCol() == 3) {
+                    return new ProjectiveTransform2D(matrix);
+                } else {
+                    return new ProjectiveTransform(matrix);
+                }
+            }
+        });
+    }
+
+    /*
+     * Inherit all the tests from GeoAPI.
+     */
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1600886&r1=1600885&r2=1600886&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Fri Jun  6 13:48:00 2014
@@ -42,6 +42,7 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.operation.matrix.AffineTransforms2DTest.class,
     org.apache.sis.referencing.operation.transform.IterationStrategyTest.class,
     org.apache.sis.referencing.operation.transform.AbstractMathTransformTest.class,
+    org.apache.sis.referencing.operation.transform.ProjectiveTransformTest.class,
     org.apache.sis.referencing.operation.transform.CopyTransformTest.class,
 
     org.apache.sis.internal.referencing.FormulasTest.class,



Mime
View raw message