commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1079350 [2/6] - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/exception/ main/java/org/apache/commons/math/linear/ main/java/org/apache/commons/math/optimization/general/ main/java/org/apache/commons/math/random/ tes...
Date Tue, 08 Mar 2011 13:42:18 GMT
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java?rev=1079350&r1=1079349&r2=1079350&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java
Tue Mar  8 13:42:16 2011
@@ -16,17 +16,16 @@
  */
 package org.apache.commons.math.linear;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.Assert;
 
 import org.apache.commons.math.TestUtils;
 import org.apache.commons.math.util.FastMath;
 import org.apache.commons.math.exception.MathUserException;
 import org.apache.commons.math.exception.DimensionMismatchException;
-import org.apache.commons.math.exception.MatrixDimensionMismatchException;
 import org.apache.commons.math.exception.OutOfRangeException;
 import org.apache.commons.math.exception.NoDataException;
 import org.apache.commons.math.exception.NumberIsTooSmallException;
-import org.apache.commons.math.exception.NonSquareMatrixException;
 import org.apache.commons.math.exception.MathIllegalArgumentException;
 import org.apache.commons.math.exception.MathIllegalStateException;
 
@@ -36,7 +35,7 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 
-public final class Array2DRowRealMatrixTest extends TestCase {
+public final class Array2DRowRealMatrixTest {
 
     // 3 x 3 identity matrix
     protected double[][] id = { {1d,0d,0d}, {0d,1d,0d}, {0d,0d,1d} };
@@ -98,33 +97,32 @@ public final class Array2DRowRealMatrixT
     protected double entryTolerance = 10E-16;
     protected double normTolerance = 10E-14;
 
-    public Array2DRowRealMatrixTest(String name) {
-        super(name);
-    }
-
     /** test dimensions */
+    @Test
     public void testDimensions() {
         Array2DRowRealMatrix m = new Array2DRowRealMatrix(testData);
         Array2DRowRealMatrix m2 = new Array2DRowRealMatrix(testData2);
-        assertEquals("testData row dimension",3,m.getRowDimension());
-        assertEquals("testData column dimension",3,m.getColumnDimension());
-        assertTrue("testData is square",m.isSquare());
-        assertEquals("testData2 row dimension",m2.getRowDimension(),2);
-        assertEquals("testData2 column dimension",m2.getColumnDimension(),3);
-        assertTrue("testData2 is not square",!m2.isSquare());
+        Assert.assertEquals("testData row dimension",3,m.getRowDimension());
+        Assert.assertEquals("testData column dimension",3,m.getColumnDimension());
+        Assert.assertTrue("testData is square",m.isSquare());
+        Assert.assertEquals("testData2 row dimension",m2.getRowDimension(),2);
+        Assert.assertEquals("testData2 column dimension",m2.getColumnDimension(),3);
+        Assert.assertTrue("testData2 is not square",!m2.isSquare());
     }
 
     /** test copy functions */
+    @Test
     public void testCopyFunctions() {
         Array2DRowRealMatrix m1 = new Array2DRowRealMatrix(testData);
         Array2DRowRealMatrix m2 = new Array2DRowRealMatrix(m1.getData());
-        assertEquals(m2,m1);
+        Assert.assertEquals(m2,m1);
         Array2DRowRealMatrix m3 = new Array2DRowRealMatrix(testData);
         Array2DRowRealMatrix m4 = new Array2DRowRealMatrix(m3.getData(), false);
-        assertEquals(m4,m3);
+        Assert.assertEquals(m4,m3);
     }
 
     /** test add */
+    @Test
     public void testAdd() {
         Array2DRowRealMatrix m = new Array2DRowRealMatrix(testData);
         Array2DRowRealMatrix mInv = new Array2DRowRealMatrix(testDataInv);
@@ -132,7 +130,7 @@ public final class Array2DRowRealMatrixT
         double[][] sumEntries = mPlusMInv.getData();
         for (int row = 0; row < m.getRowDimension(); row++) {
             for (int col = 0; col < m.getColumnDimension(); col++) {
-                assertEquals("sum entry entry",
+                Assert.assertEquals("sum entry entry",
                     testDataPlusInv[row][col],sumEntries[row][col],
                         entryTolerance);
             }
@@ -140,34 +138,38 @@ public final class Array2DRowRealMatrixT
     }
 
     /** test add failure */
+    @Test
     public void testAddFail() {
         Array2DRowRealMatrix m = new Array2DRowRealMatrix(testData);
         Array2DRowRealMatrix m2 = new Array2DRowRealMatrix(testData2);
         try {
             m.add(m2);
-            fail("MathIllegalArgumentException expected");
+            Assert.fail("MathIllegalArgumentException expected");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
     }
 
     /** test norm */
+    @Test
     public void testNorm() {
         Array2DRowRealMatrix m = new Array2DRowRealMatrix(testData);
         Array2DRowRealMatrix m2 = new Array2DRowRealMatrix(testData2);
-        assertEquals("testData norm",14d,m.getNorm(),entryTolerance);
-        assertEquals("testData2 norm",7d,m2.getNorm(),entryTolerance);
+        Assert.assertEquals("testData norm",14d,m.getNorm(),entryTolerance);
+        Assert.assertEquals("testData2 norm",7d,m2.getNorm(),entryTolerance);
     }
 
     /** test Frobenius norm */
+    @Test
     public void testFrobeniusNorm() {
         Array2DRowRealMatrix m = new Array2DRowRealMatrix(testData);
         Array2DRowRealMatrix m2 = new Array2DRowRealMatrix(testData2);
-        assertEquals("testData Frobenius norm", FastMath.sqrt(117.0), m.getFrobeniusNorm(),
entryTolerance);
-        assertEquals("testData2 Frobenius norm", FastMath.sqrt(52.0), m2.getFrobeniusNorm(),
entryTolerance);
+        Assert.assertEquals("testData Frobenius norm", FastMath.sqrt(117.0), m.getFrobeniusNorm(),
entryTolerance);
+        Assert.assertEquals("testData2 Frobenius norm", FastMath.sqrt(52.0), m2.getFrobeniusNorm(),
entryTolerance);
     }
 
      /** test m-n = m + -n */
+    @Test
     public void testPlusMinus() {
         Array2DRowRealMatrix m = new Array2DRowRealMatrix(testData);
         Array2DRowRealMatrix m2 = new Array2DRowRealMatrix(testDataInv);
@@ -175,14 +177,15 @@ public final class Array2DRowRealMatrixT
             m2.scalarMultiply(-1d).add(m),entryTolerance);
         try {
             m.subtract(new Array2DRowRealMatrix(testData2));
-            fail("Expecting illegalArgumentException");
+            Assert.fail("Expecting illegalArgumentException");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
     }
 
     /** test multiply */
-     public void testMultiply() {
+    @Test
+    public void testMultiply() {
         Array2DRowRealMatrix m = new Array2DRowRealMatrix(testData);
         Array2DRowRealMatrix mInv = new Array2DRowRealMatrix(testDataInv);
         Array2DRowRealMatrix identity = new Array2DRowRealMatrix(id);
@@ -199,7 +202,7 @@ public final class Array2DRowRealMatrixT
             m2,entryTolerance);
         try {
             m.multiply(new Array2DRowRealMatrix(bigSingular));
-            fail("Expecting illegalArgumentException");
+            Assert.fail("Expecting illegalArgumentException");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
@@ -211,6 +214,7 @@ public final class Array2DRowRealMatrixT
     private double[][] d4 = new double[][] {{1},{2},{3},{4}};
     private double[][] d5 = new double[][] {{30},{70}};
 
+    @Test
     public void testMultiply2() {
        RealMatrix m3 = new Array2DRowRealMatrix(d3);
        RealMatrix m4 = new Array2DRowRealMatrix(d4);
@@ -219,19 +223,21 @@ public final class Array2DRowRealMatrixT
    }
 
     /** test trace */
+    @Test
     public void testTrace() {
         RealMatrix m = new Array2DRowRealMatrix(id);
-        assertEquals("identity trace",3d,m.getTrace(),entryTolerance);
+        Assert.assertEquals("identity trace",3d,m.getTrace(),entryTolerance);
         m = new Array2DRowRealMatrix(testData2);
         try {
             m.getTrace();
-            fail("Expecting NonSquareMatrixException");
+            Assert.fail("Expecting NonSquareMatrixException");
         } catch (NonSquareMatrixException ex) {
             // ignored
         }
     }
 
     /** test sclarAdd */
+    @Test
     public void testScalarAdd() {
         RealMatrix m = new Array2DRowRealMatrix(testData);
         TestUtils.assertEquals("scalar add",new Array2DRowRealMatrix(testDataPlus2),
@@ -239,6 +245,7 @@ public final class Array2DRowRealMatrixT
     }
 
     /** test operate */
+    @Test
     public void testOperate() {
         RealMatrix m = new Array2DRowRealMatrix(id);
         TestUtils.assertEquals("identity operate", testVector,
@@ -248,25 +255,27 @@ public final class Array2DRowRealMatrixT
         m = new Array2DRowRealMatrix(bigSingular);
         try {
             m.operate(testVector);
-            fail("Expecting illegalArgumentException");
+            Assert.fail("Expecting illegalArgumentException");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
     }
 
     /** test issue MATH-209 */
+    @Test
     public void testMath209() {
         RealMatrix a = new Array2DRowRealMatrix(new double[][] {
                 { 1, 2 }, { 3, 4 }, { 5, 6 }
         }, false);
         double[] b = a.operate(new double[] { 1, 1 });
-        assertEquals(a.getRowDimension(), b.length);
-        assertEquals( 3.0, b[0], 1.0e-12);
-        assertEquals( 7.0, b[1], 1.0e-12);
-        assertEquals(11.0, b[2], 1.0e-12);
+        Assert.assertEquals(a.getRowDimension(), b.length);
+        Assert.assertEquals( 3.0, b[0], 1.0e-12);
+        Assert.assertEquals( 7.0, b[1], 1.0e-12);
+        Assert.assertEquals(11.0, b[2], 1.0e-12);
     }
 
     /** test transpose */
+    @Test
     public void testTranspose() {
         RealMatrix m = new Array2DRowRealMatrix(testData);
         RealMatrix mIT = new LUDecompositionImpl(m).getSolver().getInverse().transpose();
@@ -278,6 +287,7 @@ public final class Array2DRowRealMatrixT
     }
 
     /** test preMultiply by vector */
+    @Test
     public void testPremultiplyVector() {
         RealMatrix m = new Array2DRowRealMatrix(testData);
         TestUtils.assertEquals("premultiply", m.preMultiply(testVector),
@@ -287,12 +297,13 @@ public final class Array2DRowRealMatrixT
         m = new Array2DRowRealMatrix(bigSingular);
         try {
             m.preMultiply(testVector);
-            fail("expecting MathIllegalArgumentException");
+            Assert.fail("expecting MathIllegalArgumentException");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
     }
 
+    @Test
     public void testPremultiply() {
         RealMatrix m3 = new Array2DRowRealMatrix(d3);
         RealMatrix m4 = new Array2DRowRealMatrix(d4);
@@ -312,42 +323,45 @@ public final class Array2DRowRealMatrixT
                 mInv,entryTolerance);
         try {
             m.preMultiply(new Array2DRowRealMatrix(bigSingular));
-            fail("Expecting illegalArgumentException");
+            Assert.fail("Expecting illegalArgumentException");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
     }
 
+    @Test
     public void testGetVectors() {
         RealMatrix m = new Array2DRowRealMatrix(testData);
         TestUtils.assertEquals("get row",m.getRow(0),testDataRow1,entryTolerance);
         TestUtils.assertEquals("get col",m.getColumn(2),testDataCol3,entryTolerance);
         try {
             m.getRow(10);
-            fail("expecting OutOfRangeException");
+            Assert.fail("expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // ignored
         }
         try {
             m.getColumn(-1);
-            fail("expecting OutOfRangeException");
+            Assert.fail("expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // ignored
         }
     }
 
+    @Test
     public void testGetEntry() {
         RealMatrix m = new Array2DRowRealMatrix(testData);
-        assertEquals("get entry",m.getEntry(0,1),2d,entryTolerance);
+        Assert.assertEquals("get entry",m.getEntry(0,1),2d,entryTolerance);
         try {
             m.getEntry(10, 4);
-            fail ("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
     }
 
     /** test examples in user guide */
+    @Test
     public void testExamples() {
         // Create a real matrix with two rows and three columns
         double[][] matrixData = { {1d,2d,3d}, {2d,5d,3d}};
@@ -357,25 +371,26 @@ public final class Array2DRowRealMatrixT
         RealMatrix n = new Array2DRowRealMatrix(matrixData2);
         // Now multiply m by n
         RealMatrix p = m.multiply(n);
-        assertEquals(2, p.getRowDimension());
-        assertEquals(2, p.getColumnDimension());
+        Assert.assertEquals(2, p.getRowDimension());
+        Assert.assertEquals(2, p.getColumnDimension());
         // Invert p
         RealMatrix pInverse = new LUDecompositionImpl(p).getSolver().getInverse();
-        assertEquals(2, pInverse.getRowDimension());
-        assertEquals(2, pInverse.getColumnDimension());
+        Assert.assertEquals(2, pInverse.getRowDimension());
+        Assert.assertEquals(2, pInverse.getColumnDimension());
 
         // Solve example
         double[][] coefficientsData = {{2, 3, -2}, {-1, 7, 6}, {4, -3, -5}};
         RealMatrix coefficients = new Array2DRowRealMatrix(coefficientsData);
         double[] constants = {1, -2, 1};
         double[] solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants);
-        assertEquals(2 * solution[0] + 3 * solution[1] -2 * solution[2], constants[0], 1E-12);
-        assertEquals(-1 * solution[0] + 7 * solution[1] + 6 * solution[2], constants[1],
1E-12);
-        assertEquals(4 * solution[0] - 3 * solution[1] -5 * solution[2], constants[2], 1E-12);
+        Assert.assertEquals(2 * solution[0] + 3 * solution[1] -2 * solution[2], constants[0],
1E-12);
+        Assert.assertEquals(-1 * solution[0] + 7 * solution[1] + 6 * solution[2], constants[1],
1E-12);
+        Assert.assertEquals(4 * solution[0] - 3 * solution[1] -5 * solution[2], constants[2],
1E-12);
 
     }
 
     // test submatrix accessors
+    @Test
     public void testGetSubMatrix() {
         RealMatrix m = new Array2DRowRealMatrix(subTestData);
         checkGetSubMatrix(m, subRows23Cols00,  2 , 3 , 0, 0, false);
@@ -400,9 +415,9 @@ public final class Array2DRowRealMatrixT
                                    boolean mustFail) {
         try {
             RealMatrix sub = m.getSubMatrix(startRow, endRow, startColumn, endColumn);
-            assertEquals(new Array2DRowRealMatrix(reference), sub);
+            Assert.assertEquals(new Array2DRowRealMatrix(reference), sub);
             if (mustFail) {
-                fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
+                Assert.fail("Expecting OutOfRangeException or NumberIsTooSmallException or
NoDataException");
             }
         } catch (OutOfRangeException e) {
             if (!mustFail) {
@@ -424,9 +439,9 @@ public final class Array2DRowRealMatrixT
                                    boolean mustFail) {
         try {
             RealMatrix sub = m.getSubMatrix(selectedRows, selectedColumns);
-            assertEquals(new Array2DRowRealMatrix(reference), sub);
+            Assert.assertEquals(new Array2DRowRealMatrix(reference), sub);
             if (mustFail) {
-                fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
+                Assert.fail("Expecting OutOfRangeException or NumberIsTooSmallException or
NoDataException");
             }
         } catch (OutOfRangeException e) {
             if (!mustFail) {
@@ -443,6 +458,7 @@ public final class Array2DRowRealMatrixT
         }
     }
 
+    @Test
     public void testCopySubMatrix() {
         RealMatrix m = new Array2DRowRealMatrix(subTestData);
         checkCopy(m, subRows23Cols00,  2 , 3 , 0, 0, false);
@@ -471,9 +487,9 @@ public final class Array2DRowRealMatrixT
                              new double[1][1] :
                              new double[reference.length][reference[0].length];
             m.copySubMatrix(startRow, endRow, startColumn, endColumn, sub);
-            assertEquals(new Array2DRowRealMatrix(reference), new Array2DRowRealMatrix(sub));
+            Assert.assertEquals(new Array2DRowRealMatrix(reference), new Array2DRowRealMatrix(sub));
             if (mustFail) {
-                fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
+                Assert.fail("Expecting OutOfRangeException or NumberIsTooSmallException or
NoDataException");
             }
         } catch (OutOfRangeException e) {
             if (!mustFail) {
@@ -498,9 +514,9 @@ public final class Array2DRowRealMatrixT
                     new double[1][1] :
                     new double[reference.length][reference[0].length];
             m.copySubMatrix(selectedRows, selectedColumns, sub);
-            assertEquals(new Array2DRowRealMatrix(reference), new Array2DRowRealMatrix(sub));
+            Assert.assertEquals(new Array2DRowRealMatrix(reference), new Array2DRowRealMatrix(sub));
             if (mustFail) {
-                fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
+                Assert.fail("Expecting OutOfRangeException or NumberIsTooSmallException or
NoDataException");
             }
         } catch (OutOfRangeException e) {
             if (!mustFail) {
@@ -517,165 +533,173 @@ public final class Array2DRowRealMatrixT
         }
     }
 
+    @Test
     public void testGetRowMatrix() {
         RealMatrix m = new Array2DRowRealMatrix(subTestData);
         RealMatrix mRow0 = new Array2DRowRealMatrix(subRow0);
         RealMatrix mRow3 = new Array2DRowRealMatrix(subRow3);
-        assertEquals("Row0", mRow0,
+        Assert.assertEquals("Row0", mRow0,
                 m.getRowMatrix(0));
-        assertEquals("Row3", mRow3,
+        Assert.assertEquals("Row3", mRow3,
                 m.getRowMatrix(3));
         try {
             m.getRowMatrix(-1);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
         try {
             m.getRowMatrix(4);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
     }
 
+    @Test
     public void testSetRowMatrix() {
         RealMatrix m = new Array2DRowRealMatrix(subTestData);
         RealMatrix mRow3 = new Array2DRowRealMatrix(subRow3);
-        assertNotSame(mRow3, m.getRowMatrix(0));
+        Assert.assertNotSame(mRow3, m.getRowMatrix(0));
         m.setRowMatrix(0, mRow3);
-        assertEquals(mRow3, m.getRowMatrix(0));
+        Assert.assertEquals(mRow3, m.getRowMatrix(0));
         try {
             m.setRowMatrix(-1, mRow3);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
         try {
             m.setRowMatrix(0, m);
-            fail("Expecting MatrixDimensionMismatchException");
+            Assert.fail("Expecting MatrixDimensionMismatchException");
         } catch (MatrixDimensionMismatchException ex) {
             // expected
         }
     }
 
+    @Test
     public void testGetColumnMatrix() {
         RealMatrix m = new Array2DRowRealMatrix(subTestData);
         RealMatrix mColumn1 = new Array2DRowRealMatrix(subColumn1);
         RealMatrix mColumn3 = new Array2DRowRealMatrix(subColumn3);
-        assertEquals("Column1", mColumn1,
+        Assert.assertEquals("Column1", mColumn1,
                 m.getColumnMatrix(1));
-        assertEquals("Column3", mColumn3,
+        Assert.assertEquals("Column3", mColumn3,
                 m.getColumnMatrix(3));
         try {
             m.getColumnMatrix(-1);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
         try {
             m.getColumnMatrix(4);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
     }
 
+    @Test
     public void testSetColumnMatrix() {
         RealMatrix m = new Array2DRowRealMatrix(subTestData);
         RealMatrix mColumn3 = new Array2DRowRealMatrix(subColumn3);
-        assertNotSame(mColumn3, m.getColumnMatrix(1));
+        Assert.assertNotSame(mColumn3, m.getColumnMatrix(1));
         m.setColumnMatrix(1, mColumn3);
-        assertEquals(mColumn3, m.getColumnMatrix(1));
+        Assert.assertEquals(mColumn3, m.getColumnMatrix(1));
         try {
             m.setColumnMatrix(-1, mColumn3);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
         try {
             m.setColumnMatrix(0, m);
-            fail("Expecting MatrixDimensionMismatchException");
+            Assert.fail("Expecting MatrixDimensionMismatchException");
         } catch (MatrixDimensionMismatchException ex) {
             // expected
         }
     }
 
+    @Test
     public void testGetRowVector() {
         RealMatrix m = new Array2DRowRealMatrix(subTestData);
         RealVector mRow0 = new ArrayRealVector(subRow0[0]);
         RealVector mRow3 = new ArrayRealVector(subRow3[0]);
-        assertEquals("Row0", mRow0, m.getRowVector(0));
-        assertEquals("Row3", mRow3, m.getRowVector(3));
+        Assert.assertEquals("Row0", mRow0, m.getRowVector(0));
+        Assert.assertEquals("Row3", mRow3, m.getRowVector(3));
         try {
             m.getRowVector(-1);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
         try {
             m.getRowVector(4);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
     }
 
+    @Test
     public void testSetRowVector() {
         RealMatrix m = new Array2DRowRealMatrix(subTestData);
         RealVector mRow3 = new ArrayRealVector(subRow3[0]);
-        assertNotSame(mRow3, m.getRowMatrix(0));
+        Assert.assertNotSame(mRow3, m.getRowMatrix(0));
         m.setRowVector(0, mRow3);
-        assertEquals(mRow3, m.getRowVector(0));
+        Assert.assertEquals(mRow3, m.getRowVector(0));
         try {
             m.setRowVector(-1, mRow3);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
         try {
             m.setRowVector(0, new ArrayRealVector(5));
-            fail("Expecting MatrixDimensionMismatchException");
+            Assert.fail("Expecting MatrixDimensionMismatchException");
         } catch (MatrixDimensionMismatchException ex) {
             // expected
         }
     }
 
+    @Test
     public void testGetColumnVector() {
         RealMatrix m = new Array2DRowRealMatrix(subTestData);
         RealVector mColumn1 = columnToVector(subColumn1);
         RealVector mColumn3 = columnToVector(subColumn3);
-        assertEquals("Column1", mColumn1, m.getColumnVector(1));
-        assertEquals("Column3", mColumn3, m.getColumnVector(3));
+        Assert.assertEquals("Column1", mColumn1, m.getColumnVector(1));
+        Assert.assertEquals("Column3", mColumn3, m.getColumnVector(3));
         try {
             m.getColumnVector(-1);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
         try {
             m.getColumnVector(4);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
     }
 
+    @Test
     public void testSetColumnVector() {
         RealMatrix m = new Array2DRowRealMatrix(subTestData);
         RealVector mColumn3 = columnToVector(subColumn3);
-        assertNotSame(mColumn3, m.getColumnVector(1));
+        Assert.assertNotSame(mColumn3, m.getColumnVector(1));
         m.setColumnVector(1, mColumn3);
-        assertEquals(mColumn3, m.getColumnVector(1));
+        Assert.assertEquals(mColumn3, m.getColumnVector(1));
         try {
             m.setColumnVector(-1, mColumn3);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
         try {
             m.setColumnVector(0, new ArrayRealVector(5));
-            fail("Expecting MatrixDimensionMismatchException");
+            Assert.fail("Expecting MatrixDimensionMismatchException");
         } catch (MatrixDimensionMismatchException ex) {
             // expected
         }
@@ -689,43 +713,46 @@ public final class Array2DRowRealMatrixT
         return new ArrayRealVector(data, false);
     }
 
+    @Test
     public void testGetRow() {
         RealMatrix m = new Array2DRowRealMatrix(subTestData);
         checkArrays(subRow0[0], m.getRow(0));
         checkArrays(subRow3[0], m.getRow(3));
         try {
             m.getRow(-1);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
         try {
             m.getRow(4);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
     }
 
+    @Test
     public void testSetRow() {
         RealMatrix m = new Array2DRowRealMatrix(subTestData);
-        assertTrue(subRow3[0][0] != m.getRow(0)[0]);
+        Assert.assertTrue(subRow3[0][0] != m.getRow(0)[0]);
         m.setRow(0, subRow3[0]);
         checkArrays(subRow3[0], m.getRow(0));
         try {
             m.setRow(-1, subRow3[0]);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
         try {
             m.setRow(0, new double[5]);
-            fail("Expecting MatrixDimensionMismatchException");
+            Assert.fail("Expecting MatrixDimensionMismatchException");
         } catch (MatrixDimensionMismatchException ex) {
             // expected
         }
     }
 
+    @Test
     public void testGetColumn() {
         RealMatrix m = new Array2DRowRealMatrix(subTestData);
         double[] mColumn1 = columnToArray(subColumn1);
@@ -734,33 +761,34 @@ public final class Array2DRowRealMatrixT
         checkArrays(mColumn3, m.getColumn(3));
         try {
             m.getColumn(-1);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
         try {
             m.getColumn(4);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
     }
 
+    @Test
     public void testSetColumn() {
         RealMatrix m = new Array2DRowRealMatrix(subTestData);
         double[] mColumn3 = columnToArray(subColumn3);
-        assertTrue(mColumn3[0] != m.getColumn(1)[0]);
+        Assert.assertTrue(mColumn3[0] != m.getColumn(1)[0]);
         m.setColumn(1, mColumn3);
         checkArrays(mColumn3, m.getColumn(1));
         try {
             m.setColumn(-1, mColumn3);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
         try {
             m.setColumn(0, new double[5]);
-            fail("Expecting MatrixDimensionMismatchException");
+            Assert.fail("Expecting MatrixDimensionMismatchException");
         } catch (MatrixDimensionMismatchException ex) {
             // expected
         }
@@ -775,68 +803,71 @@ public final class Array2DRowRealMatrixT
     }
 
     private void checkArrays(double[] expected, double[] actual) {
-        assertEquals(expected.length, actual.length);
+        Assert.assertEquals(expected.length, actual.length);
         for (int i = 0; i < expected.length; ++i) {
-            assertEquals(expected[i], actual[i]);
+            Assert.assertEquals(expected[i], actual[i], 0);
         }
     }
 
+    @Test
     public void testEqualsAndHashCode() {
         Array2DRowRealMatrix m = new Array2DRowRealMatrix(testData);
         Array2DRowRealMatrix m1 = (Array2DRowRealMatrix) m.copy();
         Array2DRowRealMatrix mt = (Array2DRowRealMatrix) m.transpose();
-        assertTrue(m.hashCode() != mt.hashCode());
-        assertEquals(m.hashCode(), m1.hashCode());
-        assertEquals(m, m);
-        assertEquals(m, m1);
-        assertFalse(m.equals(null));
-        assertFalse(m.equals(mt));
-        assertFalse(m.equals(new Array2DRowRealMatrix(bigSingular)));
+        Assert.assertTrue(m.hashCode() != mt.hashCode());
+        Assert.assertEquals(m.hashCode(), m1.hashCode());
+        Assert.assertEquals(m, m);
+        Assert.assertEquals(m, m1);
+        Assert.assertFalse(m.equals(null));
+        Assert.assertFalse(m.equals(mt));
+        Assert.assertFalse(m.equals(new Array2DRowRealMatrix(bigSingular)));
     }
 
+    @Test
     public void testToString() {
         Array2DRowRealMatrix m = new Array2DRowRealMatrix(testData);
-        assertEquals("Array2DRowRealMatrix{{1.0,2.0,3.0},{2.0,5.0,3.0},{1.0,0.0,8.0}}",
+        Assert.assertEquals("Array2DRowRealMatrix{{1.0,2.0,3.0},{2.0,5.0,3.0},{1.0,0.0,8.0}}",
                 m.toString());
         m = new Array2DRowRealMatrix();
-        assertEquals("Array2DRowRealMatrix{}",
+        Assert.assertEquals("Array2DRowRealMatrix{}",
                 m.toString());
     }
 
+    @Test
     public void testSetSubMatrix() throws Exception {
         Array2DRowRealMatrix m = new Array2DRowRealMatrix(testData);
         m.setSubMatrix(detData2,1,1);
         RealMatrix expected = MatrixUtils.createRealMatrix
             (new double[][] {{1.0,2.0,3.0},{2.0,1.0,3.0},{1.0,2.0,4.0}});
-        assertEquals(expected, m);
+        Assert.assertEquals(expected, m);
 
         m.setSubMatrix(detData2,0,0);
         expected = MatrixUtils.createRealMatrix
             (new double[][] {{1.0,3.0,3.0},{2.0,4.0,3.0},{1.0,2.0,4.0}});
-        assertEquals(expected, m);
+        Assert.assertEquals(expected, m);
 
         m.setSubMatrix(testDataPlus2,0,0);
         expected = MatrixUtils.createRealMatrix
             (new double[][] {{3.0,4.0,5.0},{4.0,7.0,5.0},{3.0,2.0,10.0}});
-        assertEquals(expected, m);
+        Assert.assertEquals(expected, m);
 
         // dimension overflow
         try {
             m.setSubMatrix(testData,1,1);
-            fail("expecting OutOfRangeException");
+            Assert.fail("expecting OutOfRangeException");
         } catch (OutOfRangeException e) {
             // expected
         }
         // dimension underflow
         try {
             m.setSubMatrix(testData,-1,1);
-            fail("expecting OutOfRangeException");
+            Assert.fail("expecting OutOfRangeException");
         } catch (OutOfRangeException e) {
             // expected
         }
         try {
             m.setSubMatrix(testData,1,-1);
-            fail("expecting OutOfRangeException");
+            Assert.fail("expecting OutOfRangeException");
         } catch (OutOfRangeException e) {
             // expected
         }
@@ -844,20 +875,20 @@ public final class Array2DRowRealMatrixT
         // null
         try {
             m.setSubMatrix(null,1,1);
-            fail("expecting NullPointerException");
+            Assert.fail("expecting NullPointerException");
         } catch (NullPointerException e) {
             // expected
         }
         Array2DRowRealMatrix m2 = new Array2DRowRealMatrix();
         try {
             m2.setSubMatrix(testData,0,1);
-            fail("expecting MathIllegalStateException");
+            Assert.fail("expecting MathIllegalStateException");
         } catch (MathIllegalStateException e) {
             // expected
         }
         try {
             m2.setSubMatrix(testData,1,0);
-            fail("expecting MathIllegalStateException");
+            Assert.fail("expecting MathIllegalStateException");
         } catch (MathIllegalStateException e) {
             // expected
         }
@@ -865,7 +896,7 @@ public final class Array2DRowRealMatrixT
         // ragged
         try {
             m.setSubMatrix(new double[][] {{1}, {2, 3}}, 0, 0);
-            fail("expecting MathIllegalArgumentException");
+            Assert.fail("expecting MathIllegalArgumentException");
         } catch (MathIllegalArgumentException e) {
             // expected
         }
@@ -873,13 +904,13 @@ public final class Array2DRowRealMatrixT
         // empty
         try {
             m.setSubMatrix(new double[][] {{}}, 0, 0);
-            fail("expecting MathIllegalArgumentException");
+            Assert.fail("expecting MathIllegalArgumentException");
         } catch (MathIllegalArgumentException e) {
             // expected
         }
-
     }
 
+    @Test
     public void testWalk() throws MathUserException {
         int rows    = 150;
         int columns = 75;
@@ -888,87 +919,87 @@ public final class Array2DRowRealMatrixT
         m.walkInRowOrder(new SetVisitor());
         GetVisitor getVisitor = new GetVisitor();
         m.walkInOptimizedOrder(getVisitor);
-        assertEquals(rows * columns, getVisitor.getCount());
+        Assert.assertEquals(rows * columns, getVisitor.getCount());
 
         m = new Array2DRowRealMatrix(rows, columns);
         m.walkInRowOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
         getVisitor = new GetVisitor();
         m.walkInOptimizedOrder(getVisitor, 1, rows - 2, 1, columns - 2);
-        assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
+        Assert.assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
         for (int i = 0; i < rows; ++i) {
-            assertEquals(0.0, m.getEntry(i, 0), 0);
-            assertEquals(0.0, m.getEntry(i, columns - 1), 0);
+            Assert.assertEquals(0.0, m.getEntry(i, 0), 0);
+            Assert.assertEquals(0.0, m.getEntry(i, columns - 1), 0);
         }
         for (int j = 0; j < columns; ++j) {
-            assertEquals(0.0, m.getEntry(0, j), 0);
-            assertEquals(0.0, m.getEntry(rows - 1, j), 0);
+            Assert.assertEquals(0.0, m.getEntry(0, j), 0);
+            Assert.assertEquals(0.0, m.getEntry(rows - 1, j), 0);
         }
 
         m = new Array2DRowRealMatrix(rows, columns);
         m.walkInColumnOrder(new SetVisitor());
         getVisitor = new GetVisitor();
         m.walkInOptimizedOrder(getVisitor);
-        assertEquals(rows * columns, getVisitor.getCount());
+        Assert.assertEquals(rows * columns, getVisitor.getCount());
 
         m = new Array2DRowRealMatrix(rows, columns);
         m.walkInColumnOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
         getVisitor = new GetVisitor();
         m.walkInOptimizedOrder(getVisitor, 1, rows - 2, 1, columns - 2);
-        assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
+        Assert.assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
         for (int i = 0; i < rows; ++i) {
-            assertEquals(0.0, m.getEntry(i, 0), 0);
-            assertEquals(0.0, m.getEntry(i, columns - 1), 0);
+            Assert.assertEquals(0.0, m.getEntry(i, 0), 0);
+            Assert.assertEquals(0.0, m.getEntry(i, columns - 1), 0);
         }
         for (int j = 0; j < columns; ++j) {
-            assertEquals(0.0, m.getEntry(0, j), 0);
-            assertEquals(0.0, m.getEntry(rows - 1, j), 0);
+            Assert.assertEquals(0.0, m.getEntry(0, j), 0);
+            Assert.assertEquals(0.0, m.getEntry(rows - 1, j), 0);
         }
 
         m = new Array2DRowRealMatrix(rows, columns);
         m.walkInOptimizedOrder(new SetVisitor());
         getVisitor = new GetVisitor();
         m.walkInRowOrder(getVisitor);
-        assertEquals(rows * columns, getVisitor.getCount());
+        Assert.assertEquals(rows * columns, getVisitor.getCount());
 
         m = new Array2DRowRealMatrix(rows, columns);
         m.walkInOptimizedOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
         getVisitor = new GetVisitor();
         m.walkInRowOrder(getVisitor, 1, rows - 2, 1, columns - 2);
-        assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
+        Assert.assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
         for (int i = 0; i < rows; ++i) {
-            assertEquals(0.0, m.getEntry(i, 0), 0);
-            assertEquals(0.0, m.getEntry(i, columns - 1), 0);
+            Assert.assertEquals(0.0, m.getEntry(i, 0), 0);
+            Assert.assertEquals(0.0, m.getEntry(i, columns - 1), 0);
         }
         for (int j = 0; j < columns; ++j) {
-            assertEquals(0.0, m.getEntry(0, j), 0);
-            assertEquals(0.0, m.getEntry(rows - 1, j), 0);
+            Assert.assertEquals(0.0, m.getEntry(0, j), 0);
+            Assert.assertEquals(0.0, m.getEntry(rows - 1, j), 0);
         }
 
         m = new Array2DRowRealMatrix(rows, columns);
         m.walkInOptimizedOrder(new SetVisitor());
         getVisitor = new GetVisitor();
         m.walkInColumnOrder(getVisitor);
-        assertEquals(rows * columns, getVisitor.getCount());
+        Assert.assertEquals(rows * columns, getVisitor.getCount());
 
         m = new Array2DRowRealMatrix(rows, columns);
         m.walkInOptimizedOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
         getVisitor = new GetVisitor();
         m.walkInColumnOrder(getVisitor, 1, rows - 2, 1, columns - 2);
-        assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
+        Assert.assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
         for (int i = 0; i < rows; ++i) {
-            assertEquals(0.0, m.getEntry(i, 0), 0);
-            assertEquals(0.0, m.getEntry(i, columns - 1), 0);
+            Assert.assertEquals(0.0, m.getEntry(i, 0), 0);
+            Assert.assertEquals(0.0, m.getEntry(i, columns - 1), 0);
         }
         for (int j = 0; j < columns; ++j) {
-            assertEquals(0.0, m.getEntry(0, j), 0);
-            assertEquals(0.0, m.getEntry(rows - 1, j), 0);
+            Assert.assertEquals(0.0, m.getEntry(0, j), 0);
+            Assert.assertEquals(0.0, m.getEntry(rows - 1, j), 0);
         }
-
     }
 
+    @Test
     public void testSerial()  {
         Array2DRowRealMatrix m = new Array2DRowRealMatrix(testData);
-        assertEquals(m,TestUtils.serializeAndRecover(m));
+        Assert.assertEquals(m,TestUtils.serializeAndRecover(m));
     }
 
 
@@ -984,7 +1015,7 @@ public final class Array2DRowRealMatrixT
         @Override
         public void visit(int i, int j, double value) {
             ++count;
-            assertEquals(i + j / 1024.0, value, 0.0);
+            Assert.assertEquals(i + j / 1024.0, value, 0.0);
         }
         public int getCount() {
             return count;



Mime
View raw message