sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1522604 - in /sis/branches/JDK7/core/sis-referencing/src: main/java/org/apache/sis/referencing/operation/matrix/ test/java/org/apache/sis/referencing/operation/matrix/
Date Thu, 12 Sep 2013 14:53:17 GMT
Author: desruisseaux
Date: Thu Sep 12 14:53:16 2013
New Revision: 1522604

URL: http://svn.apache.org/r1522604
Log:
More simplification attempts:

1) Removed MatrixSIS.isIdentity(double tolerance) and setToIdentity() because a search in
Geotk code base has
   shown that those methods were rarely used, and when used they could be replaced by more
efficient code path.
   In particular, the 'setToIdentity()' method name was problematic because it was inappropriate
for non-square
   matrices. Removing this method avoid us the need to invent a new name.

2) Renamed (again) 'setToTranspose()' to a plain 'transpose()' because we had no other remaining
'setTo*' methods
   in MatrixSIS, and we presume that developers who want the transpose operation will look
for the "transpose" name.
   There is a slight risk of misleading name since this method performs the operation in-place,
but the fact that
   the return type is 'void' should help to avoid errors.

3) In test cases, initialize the random number generator and the matrix size in the class
constructor instead than
   in an 'initialize' method. This avoid the need to put defensive code against multiple initializations.

Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrix.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/GeneralMatrixTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix1Test.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix2Test.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix3Test.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix4Test.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java?rev=1522604&r1=1522603&r2=1522604&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
[UTF-8] Thu Sep 12 14:53:16 2013
@@ -47,7 +47,7 @@ class GeneralMatrix extends MatrixSIS {
 
     /**
      * Number of rows and columns.
-     * This is non-final only for {@link NonSquareMatrix#setToTranspose()} purpose.
+     * This is non-final only for {@link NonSquareMatrix#transpose()} purpose.
      */
     short numRow, numCol;
 
@@ -239,24 +239,12 @@ class GeneralMatrix extends MatrixSIS {
 
     /**
      * {@inheritDoc}
-     */
-    @Override
-    public final void setToIdentity() {
-        final int numCol = this.numCol; // Protection against accidental changes.
-        Arrays.fill(elements, 0);
-        for (int i=0; i<elements.length; i += numCol+1) {
-            elements[i] = 1;
-        }
-    }
-
-    /**
-     * {@inheritDoc}
      *
      * The implementation provided by {@code GeneralMatrix} is valid only for square matrix.
      * {@link NonSquareMatrix} must override.
      */
     @Override
-    public void setToTranspose() {
+    public void transpose() {
         final int numRow = this.numRow; // Protection against accidental changes.
         final int numCol = this.numCol;
         for (int j=0; j<numRow; j++) {

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java?rev=1522604&r1=1522603&r2=1522604&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
[UTF-8] Thu Sep 12 14:53:16 2013
@@ -236,7 +236,7 @@ public final class Matrices extends Stat
      * @param  tolerance The tolerance value, or 0 for a strict comparison.
      * @return {@code true} if this matrix is close to the identity matrix given the tolerance
threshold.
      *
-     * @see MatrixSIS#isIdentity(double)
+     * @see MatrixSIS#isIdentity()
      */
     public static boolean isIdentity(final Matrix matrix, final double tolerance) {
         final int numRow = matrix.getNumRow();

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java?rev=1522604&r1=1522603&r2=1522604&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java
[UTF-8] Thu Sep 12 14:53:16 2013
@@ -205,26 +205,10 @@ public final class Matrix1 extends Matri
     }
 
     /**
-     * {@inheritDoc}
-     */
-    @Override
-    public final boolean isIdentity(final double tolerance) {
-        return Math.abs(m00 - 1) <= Math.abs(tolerance);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public final void setToIdentity() {
-        m00 = 1;
-    }
-
-    /**
      * For a 1×1 matrix, this method does nothing.
      */
     @Override
-    public void setToTranspose() {
+    public void transpose() {
         // Nothing to do for a 1x1 matrix.
     }
 

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java?rev=1522604&r1=1522603&r2=1522604&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
[UTF-8] Thu Sep 12 14:53:16 2013
@@ -232,16 +232,7 @@ public final class Matrix2 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public final void setToIdentity() {
-        m01 = m10 = 0;
-        m00 = m11 = 1;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void setToTranspose() {
+    public void transpose() {
         final double swap = m10;
         m10 = m01;
         m01 = swap;

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java?rev=1522604&r1=1522603&r2=1522604&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
[UTF-8] Thu Sep 12 14:53:16 2013
@@ -272,25 +272,7 @@ public final class Matrix3 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public final void setToIdentity() {
-        setToZero();
-        m00 = m11 = m22 = 1;
-    }
-
-    /**
-     * Sets all the values in this matrix to zero.
-     */
-    private void setToZero() {
-        m00 = m01 = m02 = 0;
-        m10 = m11 = m12 = 0;
-        m20 = m21 = m22 = 0;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void setToTranspose() {
+    public void transpose() {
         double swap;
         swap = m01; m01 = m10; m10 = swap;
         swap = m02; m02 = m20; m20 = swap;

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java?rev=1522604&r1=1522603&r2=1522604&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
[UTF-8] Thu Sep 12 14:53:16 2013
@@ -319,26 +319,7 @@ public final class Matrix4 extends Matri
      * {@inheritDoc}
      */
     @Override
-    public final void setToIdentity() {
-        setToZero();
-        m00 = m11 = m22 = m33 = 1;
-    }
-
-    /**
-     * Sets all the values in this matrix to zero.
-     */
-    private void setToZero() {
-        m00 = m01 = m02 = m03 = 0;
-        m10 = m11 = m12 = m13 = 0;
-        m20 = m21 = m22 = m23 = 0;
-        m30 = m31 = m32 = m33 = 0;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void setToTranspose() {
+    public void transpose() {
         double swap;
         swap = m01; m01 = m10; m10 = swap;
         swap = m02; m02 = m20; m20 = swap;

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java?rev=1522604&r1=1522603&r2=1522604&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
(original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
Thu Sep 12 14:53:16 2013
@@ -32,7 +32,7 @@ import org.apache.sis.util.resources.Err
  *
  * <ul>
  *   <li>basic operations needed for <cite>referencing by coordinates</cite>:
- *       {@link #setToTranspose()}, {@link #inverse()}, {@link #multiply(Matrix)};</li>
+ *       {@link #transpose()}, {@link #inverse()}, {@link #multiply(Matrix)};</li>
  *   <li>some operations more specific to referencing by coordinates:
  *       {@link #isAffine()}, {@link #normalizeColumns()}.</li>
  * </ul>
@@ -121,59 +121,24 @@ public abstract class MatrixSIS implemen
 
     /**
      * Returns {@code true} if this matrix is an identity matrix.
-     * Invoking this method is equivalent to invoking <code>{@linkplain #isIdentity(double)
isIdentity}(0.0)</code>,
-     * except that it is potentially more efficient.
+     * This method is equivalent to the following code, except that it is potentially more
efficient:
+     *
+     * {@preformat java
+     *     return Matrices.isIdentity(this, 0.0);
+     * }
      *
      * @return {@code true} if this matrix is an identity matrix.
      *
-     * @see #setToIdentity()
+     * @see Matrices#isIdentity(Matrix, double)
      * @see java.awt.geom.AffineTransform#isIdentity()
      */
     @Override
     public abstract boolean isIdentity();
 
     /**
-     * Returns {@code true} if this matrix is close to an identity matrix, given a tolerance
threshold.
-     * This method is equivalent to computing the difference between this matrix and an identity
-     * matrix of identical size, and returning {@code true} if and only if all differences
are
-     * smaller than or equal to {@code tolerance}.
-     *
-     * @param  tolerance The tolerance value, or 0 for a strict comparison.
-     * @return {@code true} if this matrix is close to the identity matrix given the tolerance
threshold.
-     *
-     * @see Matrices#isIdentity(Matrix, double)
-     */
-    public boolean isIdentity(final double tolerance) {
-        return Matrices.isIdentity(this, tolerance);
-    }
-
-    /**
-     * Sets this matrix to zero everywhere except for the elements on the diagonal, which
are set to 1.
-     * If this matrix contains more rows than columns, then the extra rows will contain only
zero values.
-     * If this matrix contains more columns than rows, then the extra columns will contain
only zero values.
-     *
-     * {@section Use case}
-     * This method is often used together with {@link #isIdentity(double)} in order to workaround
rounding errors,
-     * like below:
-     *
-     * {@preformat java
-     *     if (matrix.isIdentity(1E-10)) {
-     *         matrix.setToIdentity();
-     *     }
-     * }
-     *
-     * Be aware that in the particular case of datum shifts, the matrix may be very close
to an identity matrix.
-     * Such matrices for datum shift may look like spurious results of rounding errors, but
are not.
-     *
-     * @see #isIdentity()
-     * @see java.awt.geom.AffineTransform#setToIdentity()
-     */
-    public abstract void setToIdentity();
-
-    /**
      * Sets the value of this matrix to its transpose.
      */
-    public abstract void setToTranspose();
+    public abstract void transpose();
 
     /**
      * Normalizes all columns in-place. Each columns in this matrix is considered as a vector.

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrix.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrix.java?rev=1522604&r1=1522603&r2=1522604&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrix.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrix.java
[UTF-8] Thu Sep 12 14:53:16 2013
@@ -82,7 +82,7 @@ final class NonSquareMatrix extends Gene
      * Sets the value of this matrix to its transpose.
      */
     @Override
-    public void setToTranspose() {
+    public void transpose() {
         final short numRow = this.numRow; // Protection against accidental changes before
we are done.
         final short numCol = this.numCol;
         final double[] copy = elements.clone();

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/GeneralMatrixTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/GeneralMatrixTest.java?rev=1522604&r1=1522603&r2=1522604&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/GeneralMatrixTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/GeneralMatrixTest.java
[UTF-8] Thu Sep 12 14:53:16 2013
@@ -30,24 +30,20 @@ import static org.junit.Assert.*;
  */
 public final strictfp class GeneralMatrixTest extends MatrixTestCase {
     /**
-     * Number of rows and columns, initialized by {@link #initialize(String, boolean)}.
+     * Number of rows and columns.
      */
-    private int size;
-
-    /** {@inheritDoc} */ @Override int getNumRow() {return size;}
-    /** {@inheritDoc} */ @Override int getNumCol() {return size;}
+    private final int size;
 
     /**
-     * Chooses a random size for the square matrix.
-     *
-     * @param needsRandom Ignored.
+     * Creates a test with a random size for the square matrix.
      */
-    @Override
-    void initialize(final boolean needsRandom) {
-        super.initialize(true);
+    public GeneralMatrixTest() {
         size = 5 + random.nextInt(8); // Matrix sizes from 5 to 12 inclusive.
     }
 
+    /** {@inheritDoc} */ @Override int getNumRow() {return size;}
+    /** {@inheritDoc} */ @Override int getNumCol() {return size;}
+
     /**
      * Ensures that the given matrix is an instance of the expected type.
      */

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix1Test.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix1Test.java?rev=1522604&r1=1522603&r2=1522604&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix1Test.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix1Test.java
[UTF-8] Thu Sep 12 14:53:16 2013
@@ -53,7 +53,7 @@ public final strictfp class Matrix1Test 
      */
     @Test
     public void testConstructor() {
-        final double[] elements = initConstructorTest(SIZE * SIZE);
+        final double[] elements = createRandomElements(SIZE * SIZE);
         final Matrix1 matrix = new Matrix1(
                 elements[0]);
         validate(matrix);

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix2Test.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix2Test.java?rev=1522604&r1=1522603&r2=1522604&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix2Test.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix2Test.java
[UTF-8] Thu Sep 12 14:53:16 2013
@@ -53,7 +53,7 @@ public final strictfp class Matrix2Test 
      */
     @Test
     public void testConstructor() {
-        final double[] elements = initConstructorTest(SIZE * SIZE);
+        final double[] elements = createRandomElements(SIZE * SIZE);
         final Matrix2 matrix = new Matrix2(
                 elements[0],
                 elements[1],

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix3Test.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix3Test.java?rev=1522604&r1=1522603&r2=1522604&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix3Test.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix3Test.java
[UTF-8] Thu Sep 12 14:53:16 2013
@@ -54,7 +54,7 @@ public final strictfp class Matrix3Test 
      */
     @Test
     public void testConstructor() {
-        final double[] elements = initConstructorTest(SIZE * SIZE);
+        final double[] elements = createRandomElements(SIZE * SIZE);
         final Matrix3 matrix = new Matrix3(
                 elements[0],
                 elements[1],

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix4Test.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix4Test.java?rev=1522604&r1=1522603&r2=1522604&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix4Test.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix4Test.java
[UTF-8] Thu Sep 12 14:53:16 2013
@@ -54,7 +54,7 @@ public final strictfp class Matrix4Test 
      */
     @Test
     public void testConstructor() {
-        final double[] elements = initConstructorTest(SIZE * SIZE);
+        final double[] elements = createRandomElements(SIZE * SIZE);
         final Matrix4 matrix = new Matrix4(
                 elements[ 0],
                 elements[ 1],

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java?rev=1522604&r1=1522603&r2=1522604&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java
[UTF-8] Thu Sep 12 14:53:16 2013
@@ -56,23 +56,13 @@ public abstract strictfp class MatrixTes
     /**
      * Random number generator, created by {@link #initialize(String, boolean)} when first
needed.
      */
-    Random random;
+    final Random random;
 
     /**
      * For subclasses only.
      */
     MatrixTestCase() {
-    }
-
-    /**
-     * Initializes the test. This method shall be invoked at the beginning of each test method.
-     *
-     * @param needsRandom {@code true} if the test method will need random numbers.
-     */
-    void initialize(final boolean needsRandom) {
-        if (needsRandom && random == null) {
-            random = TestUtilities.createRandomNumberGenerator();
-        }
+        random = TestUtilities.createRandomNumberGenerator();
     }
 
     /** Returns the number of rows of the matrix being tested.    */ abstract int getNumRow();
@@ -104,11 +94,10 @@ public abstract strictfp class MatrixTes
     }
 
     /**
-     * Initializes the random number generator and creates an array of the given length filled
with random values.
+     * Creates an array of the given length filled with random values.
      * This is a convenience method for the {@link testConstructor()} methods in {@code Matrix1…4Test}
subclasses.
      */
-    final double[] initConstructorTest(final int length) {
-        initialize(true);
+    final double[] createRandomElements(final int length) {
         final double[] elements = new double[length];
         for (int k=0; k<length; k++) {
             elements[k] = random.nextDouble() * 100;
@@ -126,13 +115,9 @@ public abstract strictfp class MatrixTes
      */
     @Test
     public void testGetElements() {
-        initialize(true);
         final int numRow = getNumRow();
         final int numCol = getNumCol();
-        final double[] elements = new double[numRow * numCol];
-        for (int k=0; k<elements.length; k++) {
-            elements[k] = random.nextDouble() * 100;
-        }
+        final double[] elements = createRandomElements(numRow * numCol);
         final MatrixSIS matrix = Matrices.create(numRow, numCol, elements);
         validate(matrix);
         /*
@@ -151,7 +136,6 @@ public abstract strictfp class MatrixTes
     @Test
     @DependsOnMethod("testGetElements")
     public void testSetElement() {
-        initialize(true);
         final int numRow = getNumRow();
         final int numCol = getNumCol();
         final MatrixSIS matrix = Matrices.createZero(numRow, numCol);
@@ -174,11 +158,13 @@ public abstract strictfp class MatrixTes
     /**
      * Tests {@link MatrixSIS#isIdentity()}. This method will first invoke {@link Matrices#create(int,
int)}
      * and ensure that the result contains 1 on the diagonal and 0 elsewhere.
+     *
+     * <p>This method will opportunistically tests {@link MatrixSIS#isAffine()}. The
two methods are related
+     * since {@code isIdentity()} delegates part of its work to {@code isAffine()}.</p>
      */
     @Test
     @DependsOnMethod("testSetElement")
     public void testIsIdentity() {
-        initialize(false);
         final int numRow = getNumRow();
         final int numCol = getNumCol();
         final MatrixSIS matrix = Matrices.create(numRow, numCol);
@@ -186,16 +172,19 @@ public abstract strictfp class MatrixTes
         /*
          * End of initialization - now perform the actual test.
          */
+        assertEquals("isAffine",   numRow == numCol, matrix.isAffine());
         assertEquals("isIdentity", numRow == numCol, matrix.isIdentity());
         for (int j=0; j<numRow; j++) {
             for (int i=0; i<numCol; i++) {
                 final double element = matrix.getElement(j,i);
                 assertEquals((i == j) ? 1 : 0, element, STRICT);
-                matrix.setElement(j, i, 2);
+                matrix.setElement(j, i, random.nextDouble() - 1.1);
+                assertEquals("isAffine", (numRow == numCol) && (j != numRow-1), matrix.isAffine());
                 assertFalse("isIdentity", matrix.isIdentity());
                 matrix.setElement(j, i, element);
             }
         }
+        assertEquals("isAffine",   numRow == numCol, matrix.isAffine());
         assertEquals("isIdentity", numRow == numCol, matrix.isIdentity());
     }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java?rev=1522604&r1=1522603&r2=1522604&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java
[UTF-8] Thu Sep 12 14:53:16 2013
@@ -35,24 +35,22 @@ public final strictfp class NonSquareMat
     /**
      * Number of rows and columns, initialized by {@link #initialize(String, boolean)}.
      */
-    private int numRow, numCol;
-
-    /** {@inheritDoc} */ @Override int getNumRow() {return numRow;}
-    /** {@inheritDoc} */ @Override int getNumCol() {return numCol;}
+    private final int numRow, numCol;
 
     /**
-     * Chooses a random size for the matrix and ensure that the matrix is not square.
-     *
-     * @param needsRandom Ignored.
+     * Creates a test with a random size for the matrix and ensure that the matrix is not
square.
      */
-    @Override
-    void initialize(final boolean needsRandom) {
-        super.initialize(true);
+    public NonSquareMatrixTest() {
         numRow = 5 + random.nextInt(8); // Matrix sizes from 5 to 12 inclusive.
-        do numCol = 5 + random.nextInt(8);
-        while (numCol == numRow);
+        int n;
+        do n = 5 + random.nextInt(8);
+        while (n == numRow);
+        numCol = n;
     }
 
+    /** {@inheritDoc} */ @Override int getNumRow() {return numRow;}
+    /** {@inheritDoc} */ @Override int getNumCol() {return numCol;}
+
     /**
      * Ensures that the given matrix is an instance of the expected type.
      */



Mime
View raw message