sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1600092 - in /sis/branches/JDK8: ./ core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ core/sis-referencing/src/test/java/or...
Date Wed, 04 Jun 2014 10:35:08 GMT
Author: desruisseaux
Date: Wed Jun  4 10:35:08 2014
New Revision: 1600092

URL: http://svn.apache.org/r1600092
Log:
Ported AbstractMathTransformTest.

Added:
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/AbstractMathTransformTest.java
  (with props)
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/RandomFailureTransform.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IterationStrategy.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
    sis/branches/JDK8/pom.xml

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java?rev=1600092&r1=1600091&r2=1600092&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
[UTF-8] Wed Jun  4 10:35:08 2014
@@ -59,7 +59,24 @@ import static org.apache.sis.util.Argume
  *   <li>{@link #transform(double[], int, double[], int, boolean)}</li>
  * </ul>
  *
- * However more performance may be gained by overriding the other {@code transform} method
as well.
+ * However more performance may be gained by overriding the other {@code transform} methods
as well.
+ *
+ * {@section Immutability and thread safety}
+ * This base class is immutable and thus thread-safe if the property <em>values</em>
(not necessarily the map itself)
+ * given to the constructor are also immutable. Most SIS subclasses and related classes are
immutable under similar
+ * conditions.
+ *
+ * {@section Immutability and thread safety}
+ * All Apache SIS implementations of {@code MathTransform} are immutable and thread-safe.
+ * It is highly recommended that third-party implementations be immutable and thread-safe
too.
+ * This means that unless otherwise noted in the javadoc, {@code MathTransform} instances
can
+ * be shared by many objects and passed between threads without synchronization.
+ *
+ * {@section Serialization}
+ * {@code MathTransform} may or may not be serializable, at implementation choices.
+ * Most Apache SIS implementations are serializable, but the serialized objects are not guaranteed
to be compatible
+ * with future SIS versions. Serialization, if allowed by the subclass, should be used only
for short term storage
+ * or RMI between applications running the same SIS version.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.5 (derived from geotk-1.2)
@@ -269,7 +286,7 @@ public abstract class AbstractMathTransf
      *   the same. Computing those two information in a single step can help to reduce redundant
calculation.</li>
      * </ul>
      *
-     * {@section Implementation note}
+     * {@section Note for implementors}
      * The source and destination may overlap. Consequently, implementors must read all source
      * ordinate values before to start writing the transformed ordinates in the destination
array.
      *
@@ -295,17 +312,17 @@ public abstract class AbstractMathTransf
      * Transforms a list of coordinate point ordinal values. This method is provided for
efficiently
      * transforming many points. The supplied array of ordinal values will contain packed
ordinal values.
      *
-     * <div class="note"><b>Example:</b> if the source dimension is 3,
then the ordinates will be packed
-     * in this order:
-     * <blockquote>
+     * <div class="note"><b>Example:</b> if the source dimension is 3,
then the ordinates will be packed in this order:
      * (<var>x<sub>0</sub></var>,<var>y<sub>0</sub></var>,<var>z<sub>0</sub></var>,
-     *  <var>x<sub>1</sub></var>,<var>y<sub>1</sub></var>,<var>z<sub>1</sub></var>
...).
-     * </blockquote></div>
+     *  <var>x<sub>1</sub></var>,<var>y<sub>1</sub></var>,<var>z<sub>1</sub></var>
…).
+     * </div>
      *
      * The default implementation invokes {@link #transform(double[], int, double[], int,
boolean)} in a loop,
      * using an {@linkplain IterationStrategy iteration strategy} determined from the arguments
for iterating
      * over the points.
      *
+     * <div class="note"><b>Implementation note:</b> see {@link IterationStrategy}
javadoc for a method skeleton.</div>
+     *
      * @param  srcPts The array containing the source point coordinates.
      * @param  srcOff The offset to the first point to be transformed in the source array.
      * @param  dstPts The array into which the transformed point coordinates are returned.
@@ -415,6 +432,8 @@ public abstract class AbstractMathTransf
      * Transforms a list of coordinate point ordinal values. The default implementation delegates
      * to {@link #transform(double[], int, double[], int, int)} using a temporary array of
doubles.
      *
+     * <div class="note"><b>Implementation note:</b> see {@link IterationStrategy}
javadoc for a method skeleton.</div>
+     *
      * @param srcPts The array containing the source point coordinates.
      * @param srcOff The offset to the first point to be transformed in the source array.
      * @param dstPts The array into which the transformed point coordinates are returned.
@@ -710,6 +729,9 @@ public abstract class AbstractMathTransf
      * Returns the inverse transform of this object. The default implementation returns
      * {@code this} if this transform is an {@linkplain #isIdentity() identity} transform,
      * or throws an exception otherwise. Subclasses should override this method.
+     *
+     * <div class="note"><b>Implementation note:</b> the {@link Inverse}
inner class can be used as
+     * a base for inverse transform implementations.</div>
      */
     @Override
     public MathTransform inverse() throws NoninvertibleTransformException {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IterationStrategy.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IterationStrategy.java?rev=1600092&r1=1600091&r2=1600092&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IterationStrategy.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IterationStrategy.java
[UTF-8] Wed Jun  4 10:35:08 2014
@@ -19,45 +19,59 @@ package org.apache.sis.referencing.opera
 
 /**
  * Strategy for iterating over the point arrays given to
- * {@link AbstractMathTransform#transform(double[],int,double[],int,int) transform} methods.
+ * {@link AbstractMathTransform#transform(double[], int, double[], int, int)
+ * AbstractMathTransform.transform(…)} methods.
  * If the source and destination arrays are the same and the region of the array to be written
  * overlaps the region of the array to be read, it may be necessary to iterate over the points
  * in reverse order or to copy some points in a temporary array.
- * The {@link #suggest(int, int, int, int, int)  suggest} method in this class returns a
strategy
+ * The {@link #suggest(int, int, int, int, int)  suggest(…)} method in this class returns
a strategy
  * suitable to the {@code transform} arguments.
  *
- * <p>Implementation example:</p>
+ * {@section Usage}
+ * The following code gives a skeleton for a {@code AbstractMathTransform} implementation
+ * capable to transform an array of {@code double} coordinates:
  *
  * {@preformat java
- *     public void transform(double[] srcPts, int srcOff,
- *                           double[] dstPts, int dstOff, int numPts)
- *     {
- *         int srcInc = getSourceDimension();
- *         int dstInc = getTargetDimension();
- *         if (srcPts == dstPts) {
- *             switch (IterationStrategy.suggest(srcOff, srcInc, dstOff, dstInc, numPts))
{
- *                 case ASCENDING: {
- *                     break;
- *                 }
- *                 case DESCENDING: {
- *                     srcOff += (numPts-1) * srcInc; srcInc = -srcInc;
- *                     dstOff += (numPts-1) * dstInc; dstInc = -dstInc;
- *                     break;
- *                 }
- *                 default: {
- *                     srcPts = Arrays.copyOfRange(srcPts, srcOff, srcOff + numPts*srcInc);
- *                     srcOff = 0;
- *                     break;
+ *     public class MyTransform extends AbstractMathTransform {
+ *         &#64;Override
+ *         public void transform(double[] srcPts, int srcOff,
+ *                               double[] dstPts, int dstOff, int numPts)
+ *         {
+ *             int srcInc = getSourceDimension();
+ *             int dstInc = getTargetDimension();
+ *             if (srcPts == dstPts) {
+ *                 switch (IterationStrategy.suggest(srcOff, srcInc, dstOff, dstInc, numPts))
{
+ *                     case ASCENDING: {
+ *                         break;
+ *                     }
+ *                     case DESCENDING: {
+ *                         srcOff += (numPts-1) * srcInc; srcInc = -srcInc;
+ *                         dstOff += (numPts-1) * dstInc; dstInc = -dstInc;
+ *                         break;
+ *                     }
+ *                     default: {
+ *                         srcPts = Arrays.copyOfRange(srcPts, srcOff, srcOff + numPts*srcInc);
+ *                         srcOff = 0;
+ *                         break;
+ *                     }
  *                 }
  *             }
- *         }
- *         while (--numPts >= 0) {
- *             // TODO by the implementor here:
- *             //   1. Read the coordinate starting at srcPts[srcOff].
- *             //   2. Transform it.
- *             //   3. Store the result starting at dstPts[dstOff].
- *             srcOff += srcInc;
- *             dstOff += dstInc;
+ *             while (--numPts >= 0) {
+ *                 double x = srcPts[srcOff    ];
+ *                 double y = srcPts[srcOff + 1];
+ *                 double z = srcPts[srcOff + 2];
+ *                 // Repeat as many time as needed for dimension of input points.
+ *
+ *                 // Transform (x,y,z) here.
+ *
+ *                 dstPts[dstOff    ] = x;
+ *                 dstPts[dstOff + 1] = y;
+ *                 dstPts[dstOff + 2] = z;
+ *                 // Repeat as many time as needed for dimension of output points.
+ *
+ *                 srcOff += srcInc;
+ *                 dstOff += dstInc;
+ *             }
  *         }
  *     }
  * }

Added: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/AbstractMathTransformTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/AbstractMathTransformTest.java?rev=1600092&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/AbstractMathTransformTest.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/AbstractMathTransformTest.java
[UTF-8] Wed Jun  4 10:35:08 2014
@@ -0,0 +1,248 @@
+/*
+ * 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.Arrays;
+import java.util.Random;
+import org.opengis.referencing.operation.TransformException;
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static java.lang.StrictMath.*;
+import static org.apache.sis.referencing.operation.transform.AbstractMathTransform.MAXIMUM_FAILURES;
+import static org.apache.sis.referencing.operation.transform.AbstractMathTransform.MAXIMUM_BUFFER_SIZE;
+
+
+/**
+ * Tests the {@link AbstractMathTransformTest} class.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5 (derived from geotk-3.00)
+ * @version 0.5
+ * @module
+ */
+@DependsOn(IterationStrategyTest.class)
+public final strictfp class AbstractMathTransformTest extends TestCase {
+    /**
+     * Tests the transform methods expecting at least one argument of type {@code float[]}.
+     * We will use the {@link AbstractMathTransform#transform(double[], int, double[], int,
int)}
+     * method as the reference implementation, assuming that the later has been correctly
tested
+     * by {@link IterationStrategyTest}.
+     *
+     * @throws TransformException Should never occur.
+     */
+    @Test
+    public void testTransforms() throws TransformException {
+        /*
+         * Prepares an array of double values filled with random numbers. In order for the
test
+         * to be useful, the source array must be longer than the maximum buffer size. We
also
+         * add an arbitrary amount for making AbstractMathTransform job more difficult.
+         */
+        final int length = MAXIMUM_BUFFER_SIZE * 3 + 167;
+        final float [] srcFlt = new float [length];
+        final float [] dstFlt = new float [length];
+        final double[] srcDbl = new double[length];
+        final double[] dstDbl = new double[length];
+        final double[] result = new double[length];
+        final Random random = new Random(67285);
+        for (int i=0; i<length; i++) {
+            srcDbl[i] = random.nextDouble();
+            srcFlt[i] = (float) srcDbl[i];
+        }
+        final int checksumFlt = Arrays.hashCode(srcFlt);
+        final int checksumDbl = Arrays.hashCode(srcDbl);
+        /*
+         * Tests transformation using different combinations of dimensions and offsets.
+         * The 'srcFlt' and 'srcDbl' array should never change in this test. We will
+         * check that using checksums.
+         */
+        for (int sd=1; sd<=4; sd++) {
+            for (int td=1; td<=4; td++) {
+                final PseudoTransform tr = new PseudoTransform(sd, td);
+                for (int so=0; so<=10; so++) {
+                    for (int to=0; to<=10; to++) {
+                        final int n = min((length-so)/sd, (length-to)/td);
+                        final int sublength = n * td;
+                        tr.transform(srcDbl, so, result, to, n);
+                        for (int p=0; p<=3; p++) {
+                            final boolean srcIsDouble;
+                            final boolean dstIsDouble;
+                            switch (p) {
+                                case 0: {  // float[]  -->  float[]
+                                    srcIsDouble = false;
+                                    dstIsDouble = false;
+                                    Arrays.fill(dstFlt, Float.NaN);
+                                    tr.transform(srcFlt, so, dstFlt, to, n);
+                                    break;
+                                }
+                                case 1: {  // double[]  -->  float[]
+                                    srcIsDouble = true;
+                                    dstIsDouble = false;
+                                    Arrays.fill(dstFlt, Float.NaN);
+                                    tr.transform(srcDbl, so, dstFlt, to, n);
+                                    break;
+                                }
+                                case 2: {  // float[]  -->  double[]
+                                    srcIsDouble = false;
+                                    dstIsDouble = true;
+                                    Arrays.fill(dstDbl, Double.NaN);
+                                    tr.transform(srcFlt, so, dstDbl, to, n);
+                                    break;
+                                }
+                                case 3: {  // float[]  -->  float[]  again but on the
same array.
+                                    srcIsDouble = false;
+                                    dstIsDouble = false;
+                                    System.arraycopy(srcFlt, 0, dstFlt, 0, length);
+                                    tr.transform(dstFlt, so, dstFlt, to, n);
+                                    break;
+                                }
+                                default: throw new AssertionError(p);
+                            }
+                            for (int i=0; i<sublength; i++) {
+                                final int t = to + i;
+                                final float expected = (float) result[t];
+                                final float actual = (dstIsDouble) ? (float) dstDbl[t] :
dstFlt[t];
+                                // Don't use assertEquals(...) because we don't want to accept
NaN.
+                                if (expected != actual) {
+                                    fail("Failure in transform(" +
+                                        (srcIsDouble ? "double" : "float") + "[], " + so
+ ", " +
+                                        (dstIsDouble ? "double" : "float") + "[], " + to
+ ", " + n +
+                                        ") on (input,output) points of dimension (" + sd
+ "," + td +
+                                        "): at point " + i + " (index " + (i % MAXIMUM_BUFFER_SIZE)
+
+                                        " of buffer " + (i / MAXIMUM_BUFFER_SIZE) + "), expected
" +
+                                        expected + " but got " + actual);
+                                }
+                            }
+                        }
+                    }
+                }
+                assertEquals(checksumFlt, Arrays.hashCode(srcFlt));
+                assertEquals(checksumDbl, Arrays.hashCode(srcDbl));
+            }
+        }
+    }
+
+    /**
+     * Tests the handling of {@link TransformException}. The code is expected to be tolerant
+     * up to some frequency of errors. Untransformed coordinates are expected to be set to
NaN.
+     */
+    @Test
+    @DependsOnMethod("testTransforms")
+    public void testExceptionTolerance() {
+        final int length = MAXIMUM_BUFFER_SIZE * 3 + 186;
+        final double[] dblPts = new double[length];
+        final float [] fltPts = new float [length];
+        final int[] denominators = {
+           100,  // Failures in   1% of points.
+            50,  // Failures in   2% of points.
+            10,  // Failures in  10% of points.
+             2,  // Failures in  50% of points.
+             1   // Failures in 100% of points.
+        };
+        int abandonCount = 0;
+        int completedCount = 0;
+        for (int di=0; di<denominators.length; di++) {
+            final int denominator = denominators[di];
+            final RandomFailureTransform tr = new RandomFailureTransform(denominator);
+            final int sourceDimension = tr.getSourceDimensions();
+            final int targetDimension = tr.getTargetDimensions();
+            final int numPts = length / max(sourceDimension, targetDimension);
+            for (int p=0; p<4; p++) {
+                tr.ordinal = 0;
+                try {
+                    switch (p) {
+                        case 0: {  // double[]  -->  double[]
+                            tr.fill(dblPts);
+                            tr.transform(dblPts, 0, dblPts, 0, numPts);
+                            break;
+                        }
+                        case 1: {  // double[]  -->  float[]
+                            tr.fill(dblPts);
+                            tr.transform(dblPts, 0, fltPts, 0, numPts);
+                            break;
+                        }
+                        case 2: {  // float[]  -->  double[]
+                            tr.fill(fltPts);
+                            tr.transform(fltPts, 0, dblPts, 0, numPts);
+                            break;
+                        }
+                        case 3: {  // float[]  -->  float[]
+                            tr.fill(fltPts);
+                            tr.transform(fltPts, 0, fltPts, 0, numPts);
+                            break;
+                        }
+                        default: throw new AssertionError(p);
+                    }
+                    fail("Expected at least one TransformException.");
+                } catch (TransformException exception) {
+                    /*
+                     * This is the expected path for this test. The transform may have completed
its
+                     * work despite the exception, or may have given up, depending on the
frequency
+                     * of exception occurrences. We check if the transform has completed
its work and
+                     * compare with the expected behavior for the statistical frequency in
this run.
+                     */
+                    final boolean completed = (exception.getLastCompletedTransform() == tr);
+                    final boolean expected  = MAXIMUM_BUFFER_SIZE/denominator < MAXIMUM_FAILURES;
+                    final int count = tr.failures.size();
+                    assertEquals("The completion state during pass #" + p + " (having " +
count +
+                                 " failures among " + numPts + " points = " + 100*count/numPts
+
+                                 "%) doesn't match the expected one for a statistitical frequency
of " +
+                                 100/denominator + "% of failures:", expected, completed);
+                    // TIP: if the above assertion fails, make sure that the frequencies
declared
+                    //      in the 'denominators' array are not to close to the cutoff frequency.
+                    if (completed) {
+                        completedCount++;
+                    } else {
+                        // If the transform has given up, then there is no guarantee about
the state
+                        // of the destination array so we can not continue the tests in this
run.
+                        tr.failures.clear();
+                        abandonCount++;
+                        continue;
+                    }
+                }
+                /*
+                 * Inspects each transformed coordinates. Either all ordinates are NaN, or
either
+                 * none of them are. Verifies with RandomFailureTransform if the NaN state
is the
+                 * expected one.
+                 */
+                assertFalse("TransformExceptions should have been recorded.", tr.failures.isEmpty());
+                for (int i=0; i<numPts; i++) {
+                    final int dstOff = i * targetDimension;
+                    final boolean failed = tr.failures.remove(i);
+                    final boolean targetIsDouble = (p & 1) == 0;
+                    for (int j=dstOff + targetDimension; --j >= dstOff;) {
+                        final boolean isNaN = targetIsDouble ? Double.isNaN(dblPts[j])
+                                                             : Float .isNaN(fltPts[j]);
+                        assertEquals("Unexpected NaN state.", failed, isNaN);
+                    }
+                }
+                assertTrue("Some TransformExceptions remainding.", tr.failures.isEmpty());
+            }
+        }
+        /*
+         * Following statistics depend on the value of MAXIMUM_BUFFER_SIZE and MAXIMUM_FAILURES.
+         * They may depend slightly on the generated random values if the statistical frequency
+         * of failures is close to the threshold. Our random generator is initialized with
a
+         * constant seed, so random fluctuation should not break this test.
+         */
+        assertEquals("Count of completion.", 8, completedCount);
+        assertEquals("Count of abandons.",  12, abandonCount);
+    }
+}

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

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

Added: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/RandomFailureTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/RandomFailureTransform.java?rev=1600092&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/RandomFailureTransform.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/RandomFailureTransform.java
[UTF-8] Wed Jun  4 10:35:08 2014
@@ -0,0 +1,117 @@
+/*
+ * 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.Random;
+import java.util.HashSet;
+import org.opengis.referencing.operation.Matrix;
+import org.opengis.referencing.operation.TransformException;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * A pseudo-transform where some coordinate fail to be transformed.
+ * This is used for testing robustness to transformation failures.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5 (derived from geotk-3.00)
+ * @version 0.5
+ * @module
+ */
+final strictfp class RandomFailureTransform extends PseudoTransform {
+    /**
+     * The random number generator for determining if a transform should fail.
+     */
+    private final Random random;
+
+    /**
+     * The denominator of the fraction that determines the frequency of failures.
+     * See constructor javadoc.
+     */
+    private final int denominator;
+
+    /**
+     * The {@link #ordinal} values of coordinates that failed to be transformed. This is
provided
+     * for information purpose but not used by this class. This is user's responsibility
to clear
+     * this set before to start transforming a new array.
+     */
+    public final Set<Integer> failures;
+
+    /**
+     * Incremented after every transformed point and stored in the {@link #failures} set
in
+     * case of failure. This is user's responsibility to set this field to O before to start
+     * transforming a new array.
+     */
+    public int ordinal;
+
+    /**
+     * Creates a transform for the given dimensions. The argument is the denominator of the
+     * fraction that determines the frequency of failures. For example if this value is 20,
+     * then 1/20 (i.e. 5%) of the points to transform will fail.
+     *
+     * @param denominator The denominator of the fraction that determines the frequency of
failures.
+     */
+    public RandomFailureTransform(final int denominator) {
+        super(4,3);
+        this.denominator = denominator;
+        random = new Random(891914828L * denominator);
+        failures = new HashSet<>();
+    }
+
+    /**
+     * Fills the given array with random number.
+     *
+     * @param array The array to fill.
+     */
+    public void fill(final double[] array) {
+        for (int i=0; i<array.length; i++) {
+            array[i] = random.nextDouble();
+        }
+    }
+
+    /**
+     * Fills the given array with random number.
+     *
+     * @param array The array to fill.
+     */
+    public void fill(final float[] array) {
+        for (int i=0; i<array.length; i++) {
+            array[i] = random.nextFloat();
+        }
+    }
+
+    /**
+     * Pseudo-transform a point in the given array, with intentional random failures.
+     *
+     * @throws TransformException Throws randomly at the frequency given at construction
time.
+     */
+    @Override
+    public Matrix transform(final double[] srcPts, final int srcOff,
+                            final double[] dstPts, final int dstOff,
+                            final boolean derivate) throws TransformException
+    {
+        final Matrix derivative = super.transform(srcPts, srcOff, dstPts, dstOff, derivate);
+        final int index = ordinal++;
+        if (random.nextInt(denominator) == 0) {
+            assertTrue("Clash in coordinate ordinal.", failures.add(index));
+            throw new TransformException("Random exception for testing purpose.");
+        }
+        return derivative;
+    }
+}

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

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/RandomFailureTransform.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=1600092&r1=1600091&r2=1600092&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] Wed Jun  4 10:35:08 2014
@@ -41,6 +41,7 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.operation.matrix.MatricesTest.class,
     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.internal.referencing.FormulasTest.class,
     org.apache.sis.internal.referencing.VerticalDatumTypesTest.class,

Modified: sis/branches/JDK8/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/pom.xml?rev=1600092&r1=1600091&r2=1600092&view=diff
==============================================================================
--- sis/branches/JDK8/pom.xml (original)
+++ sis/branches/JDK8/pom.xml Wed Jun  4 10:35:08 2014
@@ -567,7 +567,6 @@ Apache SIS is a free software, Java lang
           <locale>${website.locale}</locale>                    <!-- Locale
for navigation bar, help file contents, etc. -->
           <author>false</author>                                <!-- Excludes
the authors text in the generated docs. -->
           <version>false</version>                              <!-- Excludes
the version text in the generated docs. -->
-          <nosince>true</nosince>                               <!-- Omits
the "Since" sections associated with the since tags. -->
           <noqualifier>all</noqualifier>                        <!-- Omit
qualifying package name before class names in output. -->
           <quiet>true</quiet>                                   <!-- Shuts
off non-error and non-warning messages. -->
           <keywords>true</keywords>                             <!-- Adds
HTML meta keyword tags to the generated files. -->



Mime
View raw message