You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2015/01/19 19:38:31 UTC

svn commit: r1653072 - in /sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis: referencing/operation/transform/MathTransformsTest.java test/suite/ReferencingTestSuite.java

Author: desruisseaux
Date: Mon Jan 19 18:38:31 2015
New Revision: 1653072

URL: http://svn.apache.org/r1653072
Log:
Add tests.

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

Added: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java?rev=1653072&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java (added)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java [UTF-8] Mon Jan 19 18:38:31 2015
@@ -0,0 +1,89 @@
+/*
+ * 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.List;
+import org.opengis.referencing.operation.MathTransform;
+import org.apache.sis.referencing.operation.matrix.Matrix4;
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.opengis.test.Assert.*;
+
+
+/**
+ * Tests {@link MathTransforms}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5
+ * @version 0.5
+ * @module
+ */
+public final strictfp class MathTransformsTest extends TestCase {
+    /**
+     * For floating point comparisons.
+     */
+    private static final double STRICT = 0;
+
+    /**
+     * Creates a dummy transform for testing purpose.
+     * The {@code scale} and {@code scap} arguments are initially identity matrices,
+     * and will be written by this method with dummy coefficient values for testing purpose.
+     *
+     * <p><b>Implementation note:</b> we do not use {@code MathTransforms.concatenate(…)} for
+     * preventing the optimization performed for the {@link PassThroughTransform} special case.</p>
+     *
+     * @param scale The matrix applying a scale along at least one axis.
+     * @param swap  The matrix swapping two matrices.
+     */
+    private static MathTransform createConcatenateAndPassThrough(final Matrix4 scale, final Matrix4 swap) {
+        scale.m11 = 3;
+        swap.m00 = 0; swap.m01 = 1;
+        swap.m10 = 1; swap.m11 = 0;
+        MathTransform tr = ExponentialTransform1D.create(10, 1);
+        tr = PassThroughTransform.create(1, tr, 1);
+        tr = new ConcatenatedTransformDirect(MathTransforms.linear(scale), tr); // See "implementation note" above.
+        tr = new ConcatenatedTransformDirect(tr, MathTransforms.linear(swap));
+        return tr;
+    }
+
+    /**
+     * Tests {@link MathTransforms#getSteps(MathTransform)}.
+     */
+    @Test
+    public void testGetSteps() {
+        final Matrix4 scale = new Matrix4(); // Scales a value.
+        final Matrix4 swap  = new Matrix4(); // Swaps two dimensions.
+        final List<MathTransform> steps = MathTransforms.getSteps(createConcatenateAndPassThrough(scale, swap));
+        assertEquals(3, steps.size());
+        assertMatrixEquals("Step 1", scale, MathTransforms.getMatrix(steps.get(0)), STRICT);
+        assertMatrixEquals("Step 3", swap,  MathTransforms.getMatrix(steps.get(2)), STRICT);
+        assertInstanceOf  ("Step 2", PassThroughTransform.class, steps.get(1));
+    }
+
+    /**
+     * Tests {@link MathTransforms#getCore(MathTransform)}.
+     */
+    @Test
+    @DependsOnMethod("testGetSteps")
+    public void testGetCore() {
+        MathTransform tr = createConcatenateAndPassThrough(new Matrix4(), new Matrix4());
+        tr = MathTransforms.getCore(tr);
+        assertInstanceOf("The only non-ignorable part should be the exponential one.", ExponentialTransform1D.class, tr);
+    }
+}

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

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.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=1653072&r1=1653071&r2=1653072&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] Mon Jan 19 18:38:31 2015
@@ -54,6 +54,7 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.operation.transform.PassThroughTransformTest.class,
     org.apache.sis.referencing.operation.transform.ConcatenatedTransformTest.class,
     org.apache.sis.referencing.operation.transform.TransferFunctionTest.class,
+    org.apache.sis.referencing.operation.transform.MathTransformsTest.class,
 
     org.apache.sis.internal.referencing.VerticalDatumTypesTest.class,
     org.apache.sis.internal.referencing.AxisDirectionsTest.class,