sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1651144 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/referencing/operation/transform/ test/java/org/apache/sis/referencing/operation/transform/ test/java/org/apache/sis/test/suite/
Date Mon, 12 Jan 2015 17:18:29 GMT
Author: desruisseaux
Date: Mon Jan 12 17:18:29 2015
New Revision: 1651144

URL: http://svn.apache.org/r1651144
Log:
More extensive tests, and fixed a bug identified by those tests.

Added:
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1DTest.java
      - copied, changed from r1651113, sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1DTest.java
Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1D.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1DTest.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/main/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1D.java?rev=1651144&r1=1651143&r2=1651144&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1D.java
[UTF-8] Mon Jan 12 17:18:29 2015
@@ -91,7 +91,7 @@ final class ExponentialTransform1D exten
     ExponentialTransform1D(final LogarithmicTransform1D inverse) {
         this.base    = inverse.getBase();
         this.lnBase  = inverse.getLogBase();
-        this.scale   = Math.pow(base, -inverse.getOffset());
+        this.scale   = inverse.pow(-inverse.getOffset());
         this.inverse = inverse;
     }
 

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1D.java?rev=1651144&r1=1651143&r2=1651144&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1D.java
[UTF-8] Mon Jan 12 17:18:29 2015
@@ -20,6 +20,7 @@ import java.io.Serializable;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransform1D;
 import org.apache.sis.internal.util.Numerics;
+import org.apache.sis.math.MathFunctions;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.ComparisonMode;
 
@@ -80,8 +81,9 @@ class LogarithmicTransform1D extends Abs
         ArgumentChecks.ensureStrictlyPositive("base", base);
         if (base == 10) {
             return Base10.create(offset);
+        } else {
+            return NATURAL.concatenate(1 / Math.log(base), offset);
         }
-        return NATURAL.concatenate(1 / Math.log(base), offset);
     }
 
     /**
@@ -122,12 +124,12 @@ class LogarithmicTransform1D extends Abs
             final LinearTransform1D linear = (LinearTransform1D) other;
             if (applyOtherFirst) {
                 if (linear.offset == 0 && linear.scale > 0) {
-                    return create(getBase(), Math.log(linear.scale) / getLogBase() + getOffset());
+                    return create(getBase(), transform(linear.scale));
                 }
             } else {
-                final double newBase = Math.pow(getBase(), 1 / linear.scale);
+                final double newBase = pow(1 / linear.scale);
                 if (!Double.isNaN(newBase)) {
-                    return create(newBase, linear.scale * getOffset() + linear.offset);
+                    return create(newBase, linear.transform(getOffset()));
                 }
             }
         } else if (other instanceof ExponentialTransform1D) {
@@ -179,7 +181,17 @@ class LogarithmicTransform1D extends Abs
     }
 
     /**
-     * Returns the logarithm of the given value in the base given to this transform constructor.
+     * Returns the base of this logarithmic transform raised to the given power.
+     *
+     * @param value The power to raise the base.
+     * @return The base of this transform raised to the given power.
+     */
+    double pow(final double value) {
+        return Math.exp(value);
+    }
+
+    /**
+     * Returns the logarithm of the given value in the base of this logarithmic transform.
      * This method is similar to {@link #transform(double)} except that the offset is not
added.
      *
      * @param  value The value for which to compute the log.
@@ -324,6 +336,12 @@ class LogarithmicTransform1D extends Abs
 
         /** {@inheritDoc} */
         @Override
+        double pow(final double value) {
+            return MathFunctions.pow10(value);
+        }
+
+        /** {@inheritDoc} */
+        @Override
         double log(final double value) {
             return Math.log10(value);
         }
@@ -345,7 +363,7 @@ class LogarithmicTransform1D extends Abs
                 srcOff += numPts;
                 dstOff += numPts;
                 while (--numPts >= 0) {
-                    dstPts[--dstOff] = Math.log10(srcPts[srcOff++]) + offset;
+                    dstPts[--dstOff] = Math.log10(srcPts[--srcOff]) + offset;
                 }
             }
         }
@@ -361,7 +379,7 @@ class LogarithmicTransform1D extends Abs
                 srcOff += numPts;
                 dstOff += numPts;
                 while (--numPts >= 0) {
-                    dstPts[--dstOff] = (float) (Math.log10(srcPts[srcOff++]) + offset);
+                    dstPts[--dstOff] = (float) (Math.log10(srcPts[--srcOff]) + offset);
                 }
             }
         }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1DTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1DTest.java?rev=1651144&r1=1651143&r2=1651144&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1DTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1DTest.java
[UTF-8] Mon Jan 12 17:18:29 2015
@@ -34,9 +34,8 @@ import org.opengis.test.ToleranceModifie
 
 
 /**
- * Tests the {@link ExponentialTransform1D} class. This test case will also tests
- * indirectly the {@link LogarithmicTransform1D} class since it is the inverse of
- * the exponential transform.
+ * Tests the {@link ExponentialTransform1D} class. Note that this is closely related to
+ * {@link LogarithmicTransform1DTest}, since one transform is the inverse of the other.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5 (derived from geotk-3.17)
@@ -49,9 +48,9 @@ import org.opengis.test.ToleranceModifie
 })
 public final strictfp class ExponentialTransform1DTest extends MathTransformTestCase {
     /**
-     * Arbitrary parameters of the exponential transform to be tested.
+     * Arbitrary parameter of the exponential transform to be tested.
      */
-    private static final double BASE = 10, SCALE = 2;
+    static final double SCALE = 2;
 
     /**
      * Arbitrary coefficients of a linear transform to be concatenated to the exponential
transform.
@@ -59,79 +58,156 @@ public final strictfp class ExponentialT
     private static final double C0 = -3, C1 = 0.25;
 
     /**
-     * The random values to use as input, and the expected transformed values.
+     * Tolerance factor for comparison of coefficients (not coordinates).
      */
-    private double[] values, expected;
+    private static final double EPS = 1E-12;
 
     /**
-     * Generates random values for input coordinates, and allocates (but do not compute values)
-     * array for the expected transformed coordinates.
-     *
-     * @param mt The math transform which will be tested.
+     * Creates a new test case.
      */
-    private void initialize(final MathTransform1D mt) {
-        transform         = mt; // Must be set before generateRandomCoordinates(…).
+    public ExponentialTransform1DTest() {
         tolerance         = 1E-14;
         toleranceModifier = ToleranceModifier.RELATIVE;
         derivativeDeltas  = new double[] {0.001};
-        values            = generateRandomCoordinates(CoordinateDomain.RANGE_10, 0);
-        expected          = new double[values.length];
     }
 
     /**
-     * Tests the current transform using the {@link #values} as input points, and comparing
with
-     * the {@link #expected} values.
-     */
-    private void run(final Class<? extends MathTransform1D> expectedType) throws TransformException
{
+     * Tests the current transform using random values as input points, and
+     * comparing with the expected values computed using the given coefficients.
+     *
+     * The {@link #transform} field must be set before to invoke this method.
+     *
+     * @param expectedType The expected base type of the math transform.
+     * @param base         The exponent base given to the {@link ExponentialTransform1D}
constructor.
+     * @param scale        The scale factor given to the {@link ExponentialTransform1D} constructor.
+     * @param preAffine    {@code true} for applying an additional affine transform before
the transform.
+     * @param postAffine   {@code true} for applying an additional affine transform after
the transform.
+     */
+    private void run(final Class<? extends MathTransform1D> expectedType, final double
base, final double scale,
+            final boolean preAffine, final boolean postAffine) throws TransformException
+    {
         assertInstanceOf("Expected the use of mathematical identities.", expectedType, transform);
         assertFalse(transform.isIdentity());
         validate();
+
+        final double[] values = generateRandomCoordinates(CoordinateDomain.RANGE_10, 0);
+        final double[] expected = new double[values.length];
+        for (int i=0; i<values.length; i++) {
+            double value = values[i];
+            if (preAffine) {
+                value = C0 + C1*value;
+            }
+            value = scale * pow(base, value);
+            if (postAffine) {
+                value = C0 + C1*value;
+            }
+            expected[i] = value;
+        }
         verifyTransform(values, expected);
         verifyDerivative(2.5); // Test at a hard-coded point.
     }
 
     /**
-     * A single (non-concatenated) test case.
+     * Implementation of {@link #testSingle()} and {@link #testSingleWithScale()} for the
given base.
+     */
+    private void testSingle(final double base, final double scale) throws TransformException
{
+        transform = ExponentialTransform1D.create(base, scale);
+        run(ExponentialTransform1D.class, base, scale, false, false);
+    }
+
+    /**
+     * Implementation of {@link #testAffinePreConcatenation()} for the given base.
+     */
+    private void testAffinePreConcatenation(final double base) throws TransformException
{
+        transform = MathTransforms.concatenate(LinearTransform1D.create(C1, C0),
+                ExponentialTransform1D.create(base, SCALE));
+        run(ExponentialTransform1D.class, base, SCALE, true, false);
+        /*
+         * Find back the original linear coefficients as documented in the ExponentialTransform1D
class javadoc.
+         */
+        final double offset = -log(SCALE) / log(base);
+        final MathTransform1D log = LogarithmicTransform1D.create(base, offset);
+        transform = (LinearTransform1D) MathTransforms.concatenate(transform, log);
+        assertEquals("C1", C1, ((LinearTransform1D) transform).scale,  EPS);
+        assertEquals("C0", C0, ((LinearTransform1D) transform).offset, EPS);
+    }
+
+    /**
+     * Implementation of {@link #testAffinePostConcatenation()} for the given base.
+     */
+    private void testAffinePostConcatenation(final double base) throws TransformException
{
+        transform = MathTransforms.concatenate(ExponentialTransform1D.create(base, SCALE),
+                LinearTransform1D.create(C1, C0));
+        /*
+         * The inverse transforms in this test case have high rounding errors.
+         * Those errors are low for values close to zero, and increase fast for higher values.
+         * We scale the default tolerance (1E-14) by 1E+8, which give us a tolerance of 1E-6.
+         */
+        toleranceModifier = ToleranceModifiers.concatenate(toleranceModifier,
+                ToleranceModifiers.scale(EnumSet.of(CalculationType.INVERSE_TRANSFORM), 1E+8));
+        run(ConcatenatedTransformDirect1D.class, base, SCALE, false, true);
+    }
+
+    /**
+     * Implementation of {@link #testAffineConcatenations()} for the given base.
+     */
+    private void testAffineConcatenations(final double base) throws TransformException {
+        final LinearTransform1D linear = LinearTransform1D.create(C1, C0);
+        transform = MathTransforms.concatenate(linear, ExponentialTransform1D.create(base,
SCALE), linear);
+
+        // See testAffinePostConcatenation for an explanation about why we relax tolerance.
+        toleranceModifier = ToleranceModifiers.concatenate(toleranceModifier,
+                ToleranceModifiers.scale(EnumSet.of(CalculationType.INVERSE_TRANSFORM), 1E+8));
+        run(ConcatenatedTransformDirect1D.class, base, SCALE, true, true);
+    }
+
+    /**
+     * A single (non-concatenated) test case without scale.
      *
      * @throws TransformException should never happen.
      */
     @Test
     public void testSingle() throws TransformException {
-        initialize(ExponentialTransform1D.create(BASE, SCALE));
-        for (int i=0; i<values.length; i++) {
-            expected[i] = SCALE * pow(BASE, values[i]);
-        }
-        run(ExponentialTransform1D.class);
+        messageOnFailure = "Exponential transform in base 10";
+        testSingle(10, 1);
+        messageOnFailure = "Exponential transform in base E";
+        testSingle(E, 1);
+        messageOnFailure = "Exponential transform in base 8.4"; // Arbitrary base.
+        testSingle(8.4, 1);
     }
 
     /**
-     * Tests the concatenation of a linear operation before the exponential one.
+     * A single (non-concatenated) test case with a scale.
      *
      * @throws TransformException should never happen.
      */
     @Test
     @DependsOnMethod("testSingle")
+    public void testSingleWithScale() throws TransformException {
+        messageOnFailure = "Exponential transform in base 10";
+        testSingle(10, SCALE);
+        messageOnFailure = "Exponential transform in base E";
+        testSingle(E, SCALE);
+        messageOnFailure = "Exponential transform in base 8.4"; // Arbitrary base.
+        testSingle(8.4, SCALE);
+    }
+
+    /**
+     * Tests the concatenation of a linear operation before the exponential one. This test
also
+     * opportunistically verifies that the technic documented in {@link ExponentialTransform1D}
+     * javadoc for finding back the original coefficients works.
+     *
+     * @throws TransformException should never happen.
+     */
+    @Test
+    @DependsOnMethod("testSingleWithScale")
     public void testAffinePreConcatenation() throws TransformException {
-        initialize(MathTransforms.concatenate(
-                   LinearTransform1D.create(C1, C0),
-                   ExponentialTransform1D.create(BASE, SCALE)));
-        for (int i=0; i<values.length; i++) {
-            expected[i] = SCALE * pow(BASE, C0 + C1 * values[i]);
-        }
-        run(ExponentialTransform1D.class);
-        /*
-         * Find back the original linear coefficients as documented in the ExponentialTransform1D
class javadoc.
-         */
-        final double lnBase =  log(BASE);
-        final double offset = -log(SCALE) / lnBase;
-        final MathTransform1D log = LogarithmicTransform1D.create(BASE, offset);
-        for (int i=0; i<values.length; i++) {
-            expected[i] = log(expected[i]) / lnBase + offset;
-        }
-        transform = (LinearTransform1D) MathTransforms.concatenate(transform, log);
-        run(LinearTransform1D.class);
-        assertEquals(C1, ((LinearTransform1D) transform).scale,  1E-12);
-        assertEquals(C0, ((LinearTransform1D) transform).offset, 1E-12);
+        messageOnFailure = "Affine + exponential transform in base 10";
+        testAffinePreConcatenation(10);
+        messageOnFailure = "Affine + exponential transform in base E";
+        testAffinePreConcatenation(E);
+        messageOnFailure = "Affine + exponential transform in base 8.4"; // Arbitrary base.
+        testAffinePreConcatenation(8.4);
     }
 
     /**
@@ -140,41 +216,32 @@ public final strictfp class ExponentialT
      * @throws TransformException should never happen.
      */
     @Test
-    @DependsOnMethod("testSingle")
+    @DependsOnMethod("testSingleWithScale")
     public void testAffinePostConcatenation() throws TransformException {
-        initialize(MathTransforms.concatenate(
-                   ExponentialTransform1D.create(BASE, SCALE),
-                   LinearTransform1D.create(C1, C0)));
-        for (int i=0; i<values.length; i++) {
-            expected[i] = C0 + C1 * (SCALE * pow(BASE, values[i]));
-        }
-        /*
-         * The inverse transforms in this test case have high rounding errors.
-         * Those errors are low for values close to zero, and increase fast for higher values.
-         * We scale the default tolerance (1E-14) by 1E+8, which give us a tolerance of 1E-6.
-         */
-        toleranceModifier = ToleranceModifiers.concatenate(toleranceModifier,
-                ToleranceModifiers.scale(EnumSet.of(CalculationType.INVERSE_TRANSFORM), 1E+8));
-        run(ConcatenatedTransformDirect1D.class);
+        messageOnFailure = "Exponential + affine transform in base 10";
+        testAffinePostConcatenation(10);
+        messageOnFailure = "Exponential + affine transform in base E";
+        testAffinePostConcatenation(E);
+        messageOnFailure = "Exponential + affine transform in base 8.4"; // Arbitrary base.
+        testAffinePostConcatenation(8.4);
     }
 
     /**
-     * Tests the concatenation of a logarithmic operation with the exponential one.
+     * Tests the concatenation of a linear operation before and after the exponential one.
      *
      * @throws TransformException should never happen.
      */
     @Test
-    @DependsOnMethod("testSingle")
-    public void testLogarithmicConcatenation() throws TransformException {
-        final double base   = 8; // Must be different than BASE.
-        final double lnBase = log(base);
-        initialize(MathTransforms.concatenate(
-                   LogarithmicTransform1D.create(base, C0),
-                   ExponentialTransform1D.create(BASE, SCALE)));
-        for (int i=0; i<values.length; i++) {
-            values[i] = abs(values[i]) + 0.001;
-            expected[i] = SCALE * pow(BASE, log(values[i]) / lnBase + C0);
-        }
-        run(ConcatenatedTransformDirect1D.class);
+    @DependsOnMethod({
+        "testAffinePreConcatenation",
+        "testAffinePostConcatenation"
+    })
+    public void testAffineConcatenations() throws TransformException {
+        messageOnFailure = "Affine + exponential + affine transform in base 10";
+        testAffineConcatenations(10);
+        messageOnFailure = "Affine + exponential + affine transform in base E";
+        testAffineConcatenations(E);
+        messageOnFailure = "Affine + exponential + affine transform in base 8.4"; // Arbitrary
base.
+        testAffineConcatenations(8.4);
     }
 }

Copied: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1DTest.java
(from r1651113, sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1DTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1DTest.java?p2=sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1DTest.java&p1=sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1DTest.java&r1=1651113&r2=1651144&rev=1651144&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ExponentialTransform1DTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/LogarithmicTransform1DTest.java
[UTF-8] Mon Jan 12 17:18:29 2015
@@ -16,7 +16,6 @@
  */
 package org.apache.sis.referencing.operation.transform;
 
-import java.util.EnumSet;
 import org.opengis.referencing.operation.MathTransform1D;
 import org.opengis.referencing.operation.TransformException;
 import static java.lang.StrictMath.*;
@@ -28,134 +27,166 @@ import org.apache.sis.test.DependsOnMeth
 import static org.opengis.test.Assert.*;
 
 // Branch-dependent imports
-import org.opengis.test.CalculationType;
 import org.opengis.test.ToleranceModifier;
-import org.opengis.test.ToleranceModifiers;
 
 
 /**
- * Tests the {@link ExponentialTransform1D} class. This test case will also tests
- * indirectly the {@link LogarithmicTransform1D} class since it is the inverse of
- * the exponential transform.
+ * Tests the {@link LogarithmicTransform1D} class. Note that this is closely related to
+ * {@link ExponentialTransform1DTest}, since one transform is the inverse of the other.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5 (derived from geotk-3.17)
  * @version 0.5
  * @module
  */
-@DependsOn({
-    CoordinateDomainTest.class,
-    LinearTransformTest.class
-})
-public final strictfp class ExponentialTransform1DTest extends MathTransformTestCase {
+@DependsOn(ExponentialTransform1DTest.class)
+public final strictfp class LogarithmicTransform1DTest extends MathTransformTestCase {
     /**
-     * Arbitrary parameters of the exponential transform to be tested.
+     * Arbitrary parameter of the logarithmic transform to be tested.
      */
-    private static final double BASE = 10, SCALE = 2;
+    private static final double OFFSET = 1.5;
 
     /**
      * Arbitrary coefficients of a linear transform to be concatenated to the exponential
transform.
      */
-    private static final double C0 = -3, C1 = 0.25;
+    private static final double C0 = 0.75, C1 = 0.25;
 
     /**
-     * The random values to use as input, and the expected transformed values.
+     * Creates a new test case.
      */
-    private double[] values, expected;
-
-    /**
-     * Generates random values for input coordinates, and allocates (but do not compute values)
-     * array for the expected transformed coordinates.
-     *
-     * @param mt The math transform which will be tested.
-     */
-    private void initialize(final MathTransform1D mt) {
-        transform         = mt; // Must be set before generateRandomCoordinates(…).
+    public LogarithmicTransform1DTest() {
         tolerance         = 1E-14;
         toleranceModifier = ToleranceModifier.RELATIVE;
         derivativeDeltas  = new double[] {0.001};
-        values            = generateRandomCoordinates(CoordinateDomain.RANGE_10, 0);
-        expected          = new double[values.length];
     }
 
     /**
-     * Tests the current transform using the {@link #values} as input points, and comparing
with
-     * the {@link #expected} values.
-     */
-    private void run(final Class<? extends MathTransform1D> expectedType) throws TransformException
{
+     * Tests the current transform using random values as input points, and
+     * comparing with the expected values computed using the given coefficients.
+     *
+     * The {@link #transform} field must be set before to invoke this method.
+     *
+     * @param expectedType The expected base type of the math transform.
+     * @param base         The exponent base given to the {@link LogarithmicTransform1D}
constructor.
+     * @param offset       The offset given to the {@link LogarithmicTransform1D} constructor.
+     * @param preAffine    {@code true} for applying an additional affine transform before
the transform.
+     * @param postAffine   {@code true} for applying an additional affine transform after
the transform.
+     */
+    private void run(final Class<? extends MathTransform1D> expectedType, final double
base, final double offset,
+            final boolean preAffine, final boolean postAffine) throws TransformException
+    {
         assertInstanceOf("Expected the use of mathematical identities.", expectedType, transform);
         assertFalse(transform.isIdentity());
         validate();
+
+        final double[] values = generateRandomCoordinates(CoordinateDomain.RANGE_10, 0);
+        final double[] expected = new double[values.length];
+        final double lnBase = log(base);
+        for (int i=0; i<values.length; i++) {
+            double value = abs(values[i]) + 0.001; // Makes the values valid for logarithms.
+            values[i] = value;
+            if (preAffine) {
+                value = C0 + C1*value;
+            }
+            value = log(value) / lnBase + offset;
+            if (postAffine) {
+                value = C0 + C1*value;
+            }
+            expected[i] = value;
+        }
         verifyTransform(values, expected);
         verifyDerivative(2.5); // Test at a hard-coded point.
     }
 
     /**
-     * A single (non-concatenated) test case.
+     * Implementation of {@link #testSingle()} and {@link #testSingleWithOffset()} for the
given base.
+     */
+    private void testSingle(final double base, final double offset,
+            final Class<? extends MathTransform1D> expectedType) throws TransformException
+    {
+        transform = LogarithmicTransform1D.create(base, offset);
+        run(expectedType, base, offset, false, false);
+    }
+
+    /**
+     * Implementation of {@link #testAffinePreConcatenation()} for the given base.
+     */
+    private void testAffinePreConcatenation(final double base) throws TransformException
{
+        transform = MathTransforms.concatenate(LinearTransform1D.create(C1, C0),
+                LogarithmicTransform1D.create(base, OFFSET));
+        run(ConcatenatedTransformDirect1D.class, base, OFFSET, true, false);
+    }
+
+    /**
+     * Implementation of {@link #testAffinePostConcatenation()} for the given base.
+     */
+    private void testAffinePostConcatenation(final double base) throws TransformException
{
+        transform = MathTransforms.concatenate(LogarithmicTransform1D.create(base, OFFSET),
+                LinearTransform1D.create(C1, C0));
+        run(ConcatenatedTransformDirect1D.class, base, OFFSET, false, true);
+    }
+
+    /**
+     * A single (non-concatenated) test case in base 10 without offset.
      *
      * @throws TransformException should never happen.
      */
     @Test
     public void testSingle() throws TransformException {
-        initialize(ExponentialTransform1D.create(BASE, SCALE));
-        for (int i=0; i<values.length; i++) {
-            expected[i] = SCALE * pow(BASE, values[i]);
-        }
-        run(ExponentialTransform1D.class);
+        messageOnFailure = "Logarithmic transform in base 10";
+        testSingle(10, 0, LogarithmicTransform1D.class);
+        messageOnFailure = "Logarithmic transform in base E";
+        testSingle(E, 0, LogarithmicTransform1D.class);
+        messageOnFailure = "Logarithmic transform in base 8.4"; // Arbitrary base.
+        testSingle(8.4, 0, ConcatenatedTransformDirect1D.class);
     }
 
     /**
-     * Tests the concatenation of a linear operation before the exponential one.
+     * A single (non-concatenated) test case in base 10 with an offset.
      *
      * @throws TransformException should never happen.
      */
     @Test
     @DependsOnMethod("testSingle")
+    public void testSingleWithOffset() throws TransformException {
+        messageOnFailure = "Logarithmic transform in base 10";
+        testSingle(10, 0.25, LogarithmicTransform1D.class);
+        messageOnFailure = "Logarithmic transform in base E";
+        testSingle(E, 0.25, ConcatenatedTransformDirect1D.class);
+        messageOnFailure = "Logarithmic transform in base 8.4"; // Arbitrary base.
+        testSingle(8.4, 0.25, ConcatenatedTransformDirect1D.class);
+    }
+
+    /**
+     * Tests the concatenation of a linear operation before the exponential one in base 10.
+     *
+     * @throws TransformException should never happen.
+     */
+    @Test
+    @DependsOnMethod("testSingleWithOffset")
     public void testAffinePreConcatenation() throws TransformException {
-        initialize(MathTransforms.concatenate(
-                   LinearTransform1D.create(C1, C0),
-                   ExponentialTransform1D.create(BASE, SCALE)));
-        for (int i=0; i<values.length; i++) {
-            expected[i] = SCALE * pow(BASE, C0 + C1 * values[i]);
-        }
-        run(ExponentialTransform1D.class);
-        /*
-         * Find back the original linear coefficients as documented in the ExponentialTransform1D
class javadoc.
-         */
-        final double lnBase =  log(BASE);
-        final double offset = -log(SCALE) / lnBase;
-        final MathTransform1D log = LogarithmicTransform1D.create(BASE, offset);
-        for (int i=0; i<values.length; i++) {
-            expected[i] = log(expected[i]) / lnBase + offset;
-        }
-        transform = (LinearTransform1D) MathTransforms.concatenate(transform, log);
-        run(LinearTransform1D.class);
-        assertEquals(C1, ((LinearTransform1D) transform).scale,  1E-12);
-        assertEquals(C0, ((LinearTransform1D) transform).offset, 1E-12);
+        messageOnFailure = "Affine + logarithmic transform in base 10";
+        testAffinePreConcatenation(10);
+        messageOnFailure = "Affine + logarithmic transform in base E";
+        testAffinePreConcatenation(E);
+        messageOnFailure = "Affine + logarithmic transform in base 8.4";
+        testAffinePreConcatenation(8.4);
     }
 
     /**
-     * Tests the concatenation of a linear operation after the exponential one.
+     * Tests the concatenation of a linear operation after the exponential one in base 10.
      *
      * @throws TransformException should never happen.
      */
     @Test
-    @DependsOnMethod("testSingle")
+    @DependsOnMethod("testSingleWithOffset")
     public void testAffinePostConcatenation() throws TransformException {
-        initialize(MathTransforms.concatenate(
-                   ExponentialTransform1D.create(BASE, SCALE),
-                   LinearTransform1D.create(C1, C0)));
-        for (int i=0; i<values.length; i++) {
-            expected[i] = C0 + C1 * (SCALE * pow(BASE, values[i]));
-        }
-        /*
-         * The inverse transforms in this test case have high rounding errors.
-         * Those errors are low for values close to zero, and increase fast for higher values.
-         * We scale the default tolerance (1E-14) by 1E+8, which give us a tolerance of 1E-6.
-         */
-        toleranceModifier = ToleranceModifiers.concatenate(toleranceModifier,
-                ToleranceModifiers.scale(EnumSet.of(CalculationType.INVERSE_TRANSFORM), 1E+8));
-        run(ConcatenatedTransformDirect1D.class);
+        messageOnFailure = "Logarithmic + affine transform in base 10";
+        testAffinePostConcatenation(10);
+        messageOnFailure = "Logarithmic + affine transform in base E";
+        testAffinePostConcatenation(E);
+        messageOnFailure = "Logarithmic + affine transform in base 8.4";
+        testAffinePostConcatenation(8.4);
     }
 
     /**
@@ -164,17 +195,22 @@ public final strictfp class ExponentialT
      * @throws TransformException should never happen.
      */
     @Test
-    @DependsOnMethod("testSingle")
+    @DependsOnMethod("testSingleWithOffset")
     public void testLogarithmicConcatenation() throws TransformException {
-        final double base   = 8; // Must be different than BASE.
-        final double lnBase = log(base);
-        initialize(MathTransforms.concatenate(
-                   LogarithmicTransform1D.create(base, C0),
-                   ExponentialTransform1D.create(BASE, SCALE)));
+        transform = MathTransforms.concatenate(
+                LogarithmicTransform1D.create(8, C0),
+                ExponentialTransform1D.create(10, ExponentialTransform1DTest.SCALE));
+        validate();
+
+        final double lnBase = log(8);
+        final double[] values = generateRandomCoordinates(CoordinateDomain.RANGE_10, 0);
+        final double[] expected = new double[values.length];
         for (int i=0; i<values.length; i++) {
-            values[i] = abs(values[i]) + 0.001;
-            expected[i] = SCALE * pow(BASE, log(values[i]) / lnBase + C0);
+            final double value = abs(values[i]) + 0.001; // Makes the values valid for logarithms.
+            values[i] = value;
+            expected[i] = ExponentialTransform1DTest.SCALE * pow(10, log(value) / lnBase
+ C0);
         }
-        run(ConcatenatedTransformDirect1D.class);
+        verifyTransform(values, expected);
+        verifyDerivative(2.5); // Test at a hard-coded point.
     }
 }

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=1651144&r1=1651143&r2=1651144&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 12 17:18:29 2015
@@ -49,6 +49,7 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.operation.transform.ProjectiveTransformTest.class,
     org.apache.sis.referencing.operation.transform.LinearTransformTest.class,
     org.apache.sis.referencing.operation.transform.ExponentialTransform1DTest.class,
+    org.apache.sis.referencing.operation.transform.LogarithmicTransform1DTest.class,
     org.apache.sis.referencing.operation.transform.CopyTransformTest.class,
     org.apache.sis.referencing.operation.transform.PassThroughTransformTest.class,
     org.apache.sis.referencing.operation.transform.ConcatenatedTransformTest.class,



Mime
View raw message