commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1079350 [6/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/SparseFieldMatrixTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseFieldMatrixTest.java?rev=1079350&r1=1079349&r2=1079350&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseFieldMatrixTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseFieldMatrixTest.java Tue Mar  8 13:42:16 2011
@@ -16,7 +16,8 @@
  */
 package org.apache.commons.math.linear;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.Assert;
 
 import org.apache.commons.math.Field;
 import org.apache.commons.math.fraction.Fraction;
@@ -26,7 +27,6 @@ import org.apache.commons.math.exception
 import org.apache.commons.math.exception.OutOfRangeException;
 import org.apache.commons.math.exception.NumberIsTooSmallException;
 import org.apache.commons.math.exception.NullArgumentException;
-import org.apache.commons.math.exception.NonSquareMatrixException;
 import org.apache.commons.math.exception.MathIllegalArgumentException;
 
 /**
@@ -34,7 +34,7 @@ import org.apache.commons.math.exception
  *
  * @version $Revision$ $Date$
  */
-public class SparseFieldMatrixTest extends TestCase {
+public class SparseFieldMatrixTest {
     // 3 x 3 identity matrix
     protected Fraction[][] id = { {new Fraction(1), new Fraction(0), new Fraction(0) }, { new Fraction(0), new Fraction(1), new Fraction(0) }, { new Fraction(0), new Fraction(0), new Fraction(1) } };
     // Test data for group operations
@@ -107,12 +107,7 @@ public class SparseFieldMatrixTest exten
     protected double normTolerance = 10E-14;
     protected Field<Fraction> field = FractionField.getInstance();
 
-    public SparseFieldMatrixTest(String name) {
-        super(name);
-        setupFractionArrays();
-    }
-
-    private void setupFractionArrays() {
+    public SparseFieldMatrixTest() {
         try {
             testDataLU = new Fraction[][]{ { new Fraction(2), new Fraction(5), new Fraction(3) }, { new Fraction(.5d), new Fraction(-2.5d), new Fraction(6.5d) },
                     { new Fraction(0.5d), new Fraction(0.2d), new Fraction(.2d) } };
@@ -127,35 +122,36 @@ public class SparseFieldMatrixTest exten
         } catch (FractionConversionException e) {
             // ignore, can't happen
         }
-
-
     }
 
     /** test dimensions */
+    @Test
     public void testDimensions() {
         SparseFieldMatrix<Fraction> m = createSparseMatrix(testData);
         SparseFieldMatrix<Fraction> m2 = createSparseMatrix(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() {
         SparseFieldMatrix<Fraction> m1 = createSparseMatrix(testData);
         FieldMatrix<Fraction> m2 = m1.copy();
-        assertEquals(m1.getClass(), m2.getClass());
-        assertEquals((m2), m1);
+        Assert.assertEquals(m1.getClass(), m2.getClass());
+        Assert.assertEquals((m2), m1);
         SparseFieldMatrix<Fraction> m3 = createSparseMatrix(testData);
         FieldMatrix<Fraction> m4 = m3.copy();
-        assertEquals(m3.getClass(), m4.getClass());
-        assertEquals((m4), m3);
+        Assert.assertEquals(m3.getClass(), m4.getClass());
+        Assert.assertEquals((m4), m3);
     }
 
     /** test add */
+    @Test
     public void testAdd() {
         SparseFieldMatrix<Fraction> m = createSparseMatrix(testData);
         SparseFieldMatrix<Fraction> mInv = createSparseMatrix(testDataInv);
@@ -163,7 +159,7 @@ public class SparseFieldMatrixTest exten
         FieldMatrix<Fraction> mPlusMInv = m.add(mInv);
         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",
                     mDataPlusInv.getEntry(row, col).doubleValue(), mPlusMInv.getEntry(row, col).doubleValue(),
                     entryTolerance);
             }
@@ -171,12 +167,13 @@ public class SparseFieldMatrixTest exten
     }
 
     /** test add failure */
+    @Test
     public void testAddFail() {
         SparseFieldMatrix<Fraction> m = createSparseMatrix(testData);
         SparseFieldMatrix<Fraction> m2 = createSparseMatrix(testData2);
         try {
             m.add(m2);
-            fail("MathIllegalArgumentException expected");
+            Assert.fail("MathIllegalArgumentException expected");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
@@ -184,6 +181,7 @@ public class SparseFieldMatrixTest exten
 
 
     /** test m-n = m + -n */
+    @Test
     public void testPlusMinus() {
         SparseFieldMatrix<Fraction> m = createSparseMatrix(testData);
         SparseFieldMatrix<Fraction> n = createSparseMatrix(testDataInv);
@@ -191,13 +189,14 @@ public class SparseFieldMatrixTest exten
             n.scalarMultiply(new Fraction(-1)).add(m), entryTolerance);
         try {
             m.subtract(createSparseMatrix(testData2));
-            fail("Expecting illegalArgumentException");
+            Assert.fail("Expecting illegalArgumentException");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
     }
 
     /** test multiply */
+    @Test
     public void testMultiply() {
         SparseFieldMatrix<Fraction> m = createSparseMatrix(testData);
         SparseFieldMatrix<Fraction> mInv = createSparseMatrix(testDataInv);
@@ -217,7 +216,7 @@ public class SparseFieldMatrixTest exten
                 entryTolerance);
         try {
             m.multiply(createSparseMatrix(bigSingular));
-            fail("Expecting illegalArgumentException");
+            Assert.fail("Expecting illegalArgumentException");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
@@ -229,6 +228,7 @@ public class SparseFieldMatrixTest exten
     private Fraction[][] d4 = new Fraction[][] { { new Fraction(1) }, { new Fraction(2) }, { new Fraction(3) }, { new Fraction(4) } };
     private Fraction[][] d5 = new Fraction[][] { { new Fraction(30) }, { new Fraction(70) } };
 
+    @Test
     public void testMultiply2() {
         FieldMatrix<Fraction> m3 = createSparseMatrix(d3);
         FieldMatrix<Fraction> m4 = createSparseMatrix(d4);
@@ -237,19 +237,21 @@ public class SparseFieldMatrixTest exten
     }
 
     /** test trace */
+    @Test
     public void testTrace() {
         FieldMatrix<Fraction> m = createSparseMatrix(id);
-        assertEquals("identity trace", 3d, m.getTrace().doubleValue(), entryTolerance);
+        Assert.assertEquals("identity trace", 3d, m.getTrace().doubleValue(), entryTolerance);
         m = createSparseMatrix(testData2);
         try {
             m.getTrace();
-            fail("Expecting NonSquareMatrixException");
+            Assert.fail("Expecting NonSquareMatrixException");
         } catch (NonSquareMatrixException ex) {
             // ignored
         }
     }
 
     /** test sclarAdd */
+    @Test
     public void testScalarAdd() {
         FieldMatrix<Fraction> m = createSparseMatrix(testData);
         assertClose("scalar add", createSparseMatrix(testDataPlus2),
@@ -257,6 +259,7 @@ public class SparseFieldMatrixTest exten
     }
 
     /** test operate */
+    @Test
     public void testOperate() {
         FieldMatrix<Fraction> m = createSparseMatrix(id);
         assertClose("identity operate", testVector, m.operate(testVector),
@@ -266,26 +269,27 @@ public class SparseFieldMatrixTest exten
         m = createSparseMatrix(bigSingular);
         try {
             m.operate(testVector);
-            fail("Expecting illegalArgumentException");
+            Assert.fail("Expecting illegalArgumentException");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
     }
 
     /** test issue MATH-209 */
+    @Test
     public void testMath209() {
         FieldMatrix<Fraction> a = createSparseMatrix(new Fraction[][] {
                 { new Fraction(1), new Fraction(2) }, { new Fraction(3), new Fraction(4) }, { new Fraction(5), new Fraction(6) } });
         Fraction[] b = a.operate(new Fraction[] { new Fraction(1), new Fraction(1) });
-        assertEquals(a.getRowDimension(), b.length);
-        assertEquals(3.0, b[0].doubleValue(), 1.0e-12);
-        assertEquals(7.0, b[1].doubleValue(), 1.0e-12);
-        assertEquals(11.0, b[2].doubleValue(), 1.0e-12);
+        Assert.assertEquals(a.getRowDimension(), b.length);
+        Assert.assertEquals(3.0, b[0].doubleValue(), 1.0e-12);
+        Assert.assertEquals(7.0, b[1].doubleValue(), 1.0e-12);
+        Assert.assertEquals(11.0, b[2].doubleValue(), 1.0e-12);
     }
 
     /** test transpose */
+    @Test
     public void testTranspose() {
-
         FieldMatrix<Fraction> m = createSparseMatrix(testData);
         FieldMatrix<Fraction> mIT = new FieldLUDecompositionImpl<Fraction>(m).getSolver().getInverse().transpose();
         FieldMatrix<Fraction> mTI = new FieldLUDecompositionImpl<Fraction>(m.transpose()).getSolver().getInverse();
@@ -296,6 +300,7 @@ public class SparseFieldMatrixTest exten
     }
 
     /** test preMultiply by vector */
+    @Test
     public void testPremultiplyVector() {
         FieldMatrix<Fraction> m = createSparseMatrix(testData);
         assertClose("premultiply", m.preMultiply(testVector), preMultTest,
@@ -305,12 +310,13 @@ public class SparseFieldMatrixTest exten
         m = createSparseMatrix(bigSingular);
         try {
             m.preMultiply(testVector);
-            fail("expecting MathIllegalArgumentException");
+            Assert.fail("expecting MathIllegalArgumentException");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
     }
 
+    @Test
     public void testPremultiply() {
         FieldMatrix<Fraction> m3 = createSparseMatrix(d3);
         FieldMatrix<Fraction> m4 = createSparseMatrix(d4);
@@ -330,42 +336,45 @@ public class SparseFieldMatrixTest exten
                 entryTolerance);
         try {
             m.preMultiply(createSparseMatrix(bigSingular));
-            fail("Expecting illegalArgumentException");
+            Assert.fail("Expecting illegalArgumentException");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
     }
 
+    @Test
     public void testGetVectors() {
         FieldMatrix<Fraction> m = createSparseMatrix(testData);
         assertClose("get row", m.getRow(0), testDataRow1, entryTolerance);
         assertClose("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() {
         FieldMatrix<Fraction> m = createSparseMatrix(testData);
-        assertEquals("get entry", m.getEntry(0, 1).doubleValue(), 2d, entryTolerance);
+        Assert.assertEquals("get entry", m.getEntry(0, 1).doubleValue(), 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
         Fraction[][] matrixData = { { new Fraction(1), new Fraction(2), new Fraction(3) }, { new Fraction(2), new Fraction(5), new Fraction(3) } };
@@ -375,12 +384,12 @@ public class SparseFieldMatrixTest exten
         FieldMatrix<Fraction> n = createSparseMatrix(matrixData2);
         // Now multiply m by n
         FieldMatrix<Fraction> p = m.multiply(n);
-        assertEquals(2, p.getRowDimension());
-        assertEquals(2, p.getColumnDimension());
+        Assert.assertEquals(2, p.getRowDimension());
+        Assert.assertEquals(2, p.getColumnDimension());
         // Invert p
         FieldMatrix<Fraction> pInverse = new FieldLUDecompositionImpl<Fraction>(p).getSolver().getInverse();
-        assertEquals(2, pInverse.getRowDimension());
-        assertEquals(2, pInverse.getColumnDimension());
+        Assert.assertEquals(2, pInverse.getRowDimension());
+        Assert.assertEquals(2, pInverse.getColumnDimension());
 
         // Solve example
         Fraction[][] coefficientsData = { { new Fraction(2), new Fraction(3), new Fraction(-2) }, { new Fraction(-1), new Fraction(7), new Fraction(6) },
@@ -388,16 +397,17 @@ public class SparseFieldMatrixTest exten
         FieldMatrix<Fraction> coefficients = createSparseMatrix(coefficientsData);
         Fraction[] constants = { new Fraction(1), new Fraction(-2), new Fraction(1) };
         Fraction[] solution = new FieldLUDecompositionImpl<Fraction>(coefficients).getSolver().solve(constants);
-        assertEquals((new Fraction(2).multiply((solution[0])).add(new Fraction(3).multiply(solution[1])).subtract(new Fraction(2).multiply(solution[2]))).doubleValue(),
+        Assert.assertEquals((new Fraction(2).multiply((solution[0])).add(new Fraction(3).multiply(solution[1])).subtract(new Fraction(2).multiply(solution[2]))).doubleValue(),
                 constants[0].doubleValue(), 1E-12);
-        assertEquals(((new Fraction(-1).multiply(solution[0])).add(new Fraction(7).multiply(solution[1])).add(new Fraction(6).multiply(solution[2]))).doubleValue(),
+        Assert.assertEquals(((new Fraction(-1).multiply(solution[0])).add(new Fraction(7).multiply(solution[1])).add(new Fraction(6).multiply(solution[2]))).doubleValue(),
                 constants[1].doubleValue(), 1E-12);
-        assertEquals(((new Fraction(4).multiply(solution[0])).subtract(new Fraction(3).multiply( solution[1])).subtract(new Fraction(5).multiply(solution[2]))).doubleValue(),
+        Assert.assertEquals(((new Fraction(4).multiply(solution[0])).subtract(new Fraction(3).multiply( solution[1])).subtract(new Fraction(5).multiply(solution[2]))).doubleValue(),
                 constants[2].doubleValue(), 1E-12);
 
     }
 
     // test submatrix accessors
+    @Test
     public void testSubMatrix() {
         FieldMatrix<Fraction> m = createSparseMatrix(subTestData);
         FieldMatrix<Fraction> mRows23Cols00 = createSparseMatrix(subRows23Cols00);
@@ -408,135 +418,139 @@ public class SparseFieldMatrixTest exten
         FieldMatrix<Fraction> mRows03Cols123 = createSparseMatrix(subRows03Cols123);
         FieldMatrix<Fraction> mRows20Cols123 = createSparseMatrix(subRows20Cols123);
         FieldMatrix<Fraction> mRows31Cols31 = createSparseMatrix(subRows31Cols31);
-        assertEquals("Rows23Cols00", mRows23Cols00, m.getSubMatrix(2, 3, 0, 0));
-        assertEquals("Rows00Cols33", mRows00Cols33, m.getSubMatrix(0, 0, 3, 3));
-        assertEquals("Rows01Cols23", mRows01Cols23, m.getSubMatrix(0, 1, 2, 3));
-        assertEquals("Rows02Cols13", mRows02Cols13,
+        Assert.assertEquals("Rows23Cols00", mRows23Cols00, m.getSubMatrix(2, 3, 0, 0));
+        Assert.assertEquals("Rows00Cols33", mRows00Cols33, m.getSubMatrix(0, 0, 3, 3));
+        Assert.assertEquals("Rows01Cols23", mRows01Cols23, m.getSubMatrix(0, 1, 2, 3));
+        Assert.assertEquals("Rows02Cols13", mRows02Cols13,
             m.getSubMatrix(new int[] { 0, 2 }, new int[] { 1, 3 }));
-        assertEquals("Rows03Cols12", mRows03Cols12,
+        Assert.assertEquals("Rows03Cols12", mRows03Cols12,
             m.getSubMatrix(new int[] { 0, 3 }, new int[] { 1, 2 }));
-        assertEquals("Rows03Cols123", mRows03Cols123,
+        Assert.assertEquals("Rows03Cols123", mRows03Cols123,
             m.getSubMatrix(new int[] { 0, 3 }, new int[] { 1, 2, 3 }));
-        assertEquals("Rows20Cols123", mRows20Cols123,
+        Assert.assertEquals("Rows20Cols123", mRows20Cols123,
             m.getSubMatrix(new int[] { 2, 0 }, new int[] { 1, 2, 3 }));
-        assertEquals("Rows31Cols31", mRows31Cols31,
+        Assert.assertEquals("Rows31Cols31", mRows31Cols31,
             m.getSubMatrix(new int[] { 3, 1 }, new int[] { 3, 1 }));
-        assertEquals("Rows31Cols31", mRows31Cols31,
+        Assert.assertEquals("Rows31Cols31", mRows31Cols31,
             m.getSubMatrix(new int[] { 3, 1 }, new int[] { 3, 1 }));
 
         try {
             m.getSubMatrix(1, 0, 2, 4);
-            fail("Expecting NumberIsTooSmallException");
+            Assert.fail("Expecting NumberIsTooSmallException");
         } catch (NumberIsTooSmallException ex) {
             // expected
         }
         try {
             m.getSubMatrix(-1, 1, 2, 2);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
         try {
             m.getSubMatrix(1, 0, 2, 2);
-            fail("Expecting NumberIsTooSmallException");
+            Assert.fail("Expecting NumberIsTooSmallException");
         } catch (NumberIsTooSmallException ex) {
             // expected
         }
         try {
             m.getSubMatrix(1, 0, 2, 4);
-            fail("Expecting NumberIsTooSmallException");
+            Assert.fail("Expecting NumberIsTooSmallException");
         } catch (NumberIsTooSmallException ex) {
             // expected
         }
         try {
             m.getSubMatrix(new int[] {}, new int[] { 0 });
-            fail("Expecting NoDataException");
+            Assert.fail("Expecting NoDataException");
         } catch (NoDataException ex) {
             // expected
         }
         try {
             m.getSubMatrix(new int[] { 0 }, new int[] { 4 });
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
     }
 
+    @Test
     public void testGetRowMatrix() {
         FieldMatrix<Fraction> m = createSparseMatrix(subTestData);
         FieldMatrix<Fraction> mRow0 = createSparseMatrix(subRow0);
         FieldMatrix<Fraction> mRow3 = createSparseMatrix(subRow3);
-        assertEquals("Row0", mRow0, m.getRowMatrix(0));
-        assertEquals("Row3", mRow3, m.getRowMatrix(3));
+        Assert.assertEquals("Row0", mRow0, m.getRowMatrix(0));
+        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 testGetColumnMatrix() {
         FieldMatrix<Fraction> m = createSparseMatrix(subTestData);
         FieldMatrix<Fraction> mColumn1 = createSparseMatrix(subColumn1);
         FieldMatrix<Fraction> mColumn3 = createSparseMatrix(subColumn3);
-        assertEquals("Column1", mColumn1, m.getColumnMatrix(1));
-        assertEquals("Column3", mColumn3, m.getColumnMatrix(3));
+        Assert.assertEquals("Column1", mColumn1, m.getColumnMatrix(1));
+        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 testGetRowVector() {
         FieldMatrix<Fraction> m = createSparseMatrix(subTestData);
         FieldVector<Fraction> mRow0 = new ArrayFieldVector<Fraction>(subRow0[0]);
         FieldVector<Fraction> mRow3 = new ArrayFieldVector<Fraction>(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 testGetColumnVector() {
         FieldMatrix<Fraction> m = createSparseMatrix(subTestData);
         FieldVector<Fraction> mColumn1 = columnToVector(subColumn1);
         FieldVector<Fraction> 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
         }
@@ -550,45 +564,47 @@ public class SparseFieldMatrixTest exten
         return new ArrayFieldVector<Fraction>(data, false);
     }
 
+    @Test
     public void testEqualsAndHashCode() {
         SparseFieldMatrix<Fraction> m = createSparseMatrix(testData);
         SparseFieldMatrix<Fraction> m1 = (SparseFieldMatrix<Fraction>) m.copy();
         SparseFieldMatrix<Fraction> mt = (SparseFieldMatrix<Fraction>) 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(createSparseMatrix(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(createSparseMatrix(bigSingular)));
     }
 
     /* Disable for now
     public void testToString() {
         SparseFieldMatrix<Fraction> m = createSparseMatrix(testData);
-        assertEquals("SparseFieldMatrix<Fraction>{{1.0,2.0,3.0},{2.0,5.0,3.0},{1.0,0.0,8.0}}",
+        Assert.assertEquals("SparseFieldMatrix<Fraction>{{1.0,2.0,3.0},{2.0,5.0,3.0},{1.0,0.0,8.0}}",
             m.toString());
         m = new SparseFieldMatrix<Fraction>(field, 1, 1);
-        assertEquals("SparseFieldMatrix<Fraction>{{0.0}}", m.toString());
+        Assert.assertEquals("SparseFieldMatrix<Fraction>{{0.0}}", m.toString());
     }
     */
 
+    @Test
     public void testSetSubMatrix() throws Exception {
         SparseFieldMatrix<Fraction> m = createSparseMatrix(testData);
         m.setSubMatrix(detData2, 1, 1);
         FieldMatrix<Fraction> expected = createSparseMatrix(new Fraction[][] {
                 { new Fraction(1), new Fraction(2), new Fraction(3) }, { new Fraction(2), new Fraction(1), new Fraction(3) }, { new Fraction(1), new Fraction(2), new Fraction(4) } });
-        assertEquals(expected, m);
+        Assert.assertEquals(expected, m);
 
         m.setSubMatrix(detData2, 0, 0);
         expected = createSparseMatrix(new Fraction[][] {
                 { new Fraction(1), new Fraction(3), new Fraction(3) }, { new Fraction(2), new Fraction(4), new Fraction(3) }, { new Fraction(1), new Fraction(2), new Fraction(4) } });
-        assertEquals(expected, m);
+        Assert.assertEquals(expected, m);
 
         m.setSubMatrix(testDataPlus2, 0, 0);
         expected = createSparseMatrix(new Fraction[][] {
                 { new Fraction(3), new Fraction(4), new Fraction(5) }, { new Fraction(4), new Fraction(7), new Fraction(5) }, { new Fraction(3), new Fraction(2), new Fraction(10) } });
-        assertEquals(expected, m);
+        Assert.assertEquals(expected, m);
 
         // javadoc example
         SparseFieldMatrix<Fraction> matrix =
@@ -597,25 +613,25 @@ public class SparseFieldMatrixTest exten
         matrix.setSubMatrix(new Fraction[][] { { new Fraction(3), new Fraction(4) }, { new Fraction(5), new Fraction(6) } }, 1, 1);
         expected = createSparseMatrix(new Fraction[][] {
                 { new Fraction(1), new Fraction(2), new Fraction(3), new Fraction(4) }, { new Fraction(5), new Fraction(3), new Fraction(4), new Fraction(8) }, { new Fraction(9), new Fraction(5), new Fraction(6), new Fraction(2) } });
-        assertEquals(expected, matrix);
+        Assert.assertEquals(expected, matrix);
 
         // 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
         }
@@ -623,13 +639,13 @@ public class SparseFieldMatrixTest exten
         // null
         try {
             m.setSubMatrix(null, 1, 1);
-            fail("expecting NullArgumentException");
+            Assert.fail("expecting NullArgumentException");
         } catch (NullArgumentException e) {
             // expected
         }
         try {
             new SparseFieldMatrix<Fraction>(field, 0, 0);
-            fail("expecting MathIllegalArgumentException");
+            Assert.fail("expecting MathIllegalArgumentException");
         } catch (MathIllegalArgumentException e) {
             // expected
         }
@@ -637,7 +653,7 @@ public class SparseFieldMatrixTest exten
         // ragged
         try {
             m.setSubMatrix(new Fraction[][] { { new Fraction(1) }, { new Fraction(2), new Fraction(3) } }, 0, 0);
-            fail("expecting MathIllegalArgumentException");
+            Assert.fail("expecting MathIllegalArgumentException");
         } catch (MathIllegalArgumentException e) {
             // expected
         }
@@ -645,11 +661,10 @@ public class SparseFieldMatrixTest exten
         // empty
         try {
             m.setSubMatrix(new Fraction[][] { {} }, 0, 0);
-            fail("expecting MathIllegalArgumentException");
+            Assert.fail("expecting MathIllegalArgumentException");
         } catch (MathIllegalArgumentException e) {
             // expected
         }
-
     }
 
     // --------------- -----------------Protected methods
@@ -659,7 +674,7 @@ public class SparseFieldMatrixTest exten
             double tolerance) {
         for(int i=0; i < m.getRowDimension(); i++){
             for(int j=0; j < m.getColumnDimension(); j++){
-                assertEquals(msg, m.getEntry(i,j).doubleValue(), n.getEntry(i,j).doubleValue(), tolerance);
+                Assert.assertEquals(msg, m.getEntry(i,j).doubleValue(), n.getEntry(i,j).doubleValue(), tolerance);
             }
 
         }
@@ -669,10 +684,10 @@ public class SparseFieldMatrixTest exten
     protected void assertClose(String msg, Fraction[] m, Fraction[] n,
             double tolerance) {
         if (m.length != n.length) {
-            fail("vectors not same length");
+            Assert.fail("vectors not same length");
         }
         for (int i = 0; i < m.length; i++) {
-            assertEquals(msg + " " + i + " elements differ", m[i].doubleValue(), n[i].doubleValue(),
+            Assert.assertEquals(msg + " " + i + " elements differ", m[i].doubleValue(), n[i].doubleValue(),
                     tolerance);
         }
     }
@@ -686,5 +701,4 @@ public class SparseFieldMatrixTest exten
         }
         return matrix;
     }
-
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java?rev=1079350&r1=1079349&r2=1079350&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java Tue Mar  8 13:42:16 2011
@@ -16,13 +16,13 @@
  */
 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.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;
 
 /**
@@ -31,7 +31,7 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date: 2008-11-07 06:48:13 -0800 (Fri, 07 Nov
  *          2008) $
  */
-public final class SparseRealMatrixTest extends TestCase {
+public final class SparseRealMatrixTest {
 
     // 3 x 3 identity matrix
     protected double[][] id = { { 1d, 0d, 0d }, { 0d, 1d, 0d }, { 0d, 0d, 1d } };
@@ -107,35 +107,34 @@ public final class SparseRealMatrixTest 
     protected double entryTolerance = 10E-16;
     protected double normTolerance = 10E-14;
 
-    public SparseRealMatrixTest(String name) {
-        super(name);
-    }
-
     /** test dimensions */
+    @Test
     public void testDimensions() {
         OpenMapRealMatrix m = createSparseMatrix(testData);
         OpenMapRealMatrix m2 = createSparseMatrix(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() {
         OpenMapRealMatrix m1 = createSparseMatrix(testData);
         RealMatrix m2 = m1.copy();
-        assertEquals(m1.getClass(), m2.getClass());
-        assertEquals((m2), m1);
+        Assert.assertEquals(m1.getClass(), m2.getClass());
+        Assert.assertEquals((m2), m1);
         OpenMapRealMatrix m3 = createSparseMatrix(testData);
         RealMatrix m4 = m3.copy();
-        assertEquals(m3.getClass(), m4.getClass());
-        assertEquals((m4), m3);
+        Assert.assertEquals(m3.getClass(), m4.getClass());
+        Assert.assertEquals((m4), m3);
     }
 
     /** test add */
+    @Test
     public void testAdd() {
         OpenMapRealMatrix m = createSparseMatrix(testData);
         OpenMapRealMatrix mInv = createSparseMatrix(testDataInv);
@@ -143,7 +142,7 @@ public final class SparseRealMatrixTest 
         RealMatrix mPlusMInv = m.add(mInv);
         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",
                     mDataPlusInv.getEntry(row, col), mPlusMInv.getEntry(row, col),
                     entryTolerance);
             }
@@ -151,26 +150,29 @@ public final class SparseRealMatrixTest 
     }
 
     /** test add failure */
+    @Test
     public void testAddFail() {
         OpenMapRealMatrix m = createSparseMatrix(testData);
         OpenMapRealMatrix m2 = createSparseMatrix(testData2);
         try {
             m.add(m2);
-            fail("MathIllegalArgumentException expected");
+            Assert.fail("MathIllegalArgumentException expected");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
     }
 
     /** test norm */
+    @Test
     public void testNorm() {
         OpenMapRealMatrix m = createSparseMatrix(testData);
         OpenMapRealMatrix m2 = createSparseMatrix(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 m-n = m + -n */
+    @Test
     public void testPlusMinus() {
         OpenMapRealMatrix m = createSparseMatrix(testData);
         OpenMapRealMatrix n = createSparseMatrix(testDataInv);
@@ -178,13 +180,14 @@ public final class SparseRealMatrixTest 
             n.scalarMultiply(-1d).add(m), entryTolerance);
         try {
             m.subtract(createSparseMatrix(testData2));
-            fail("Expecting illegalArgumentException");
+            Assert.fail("Expecting illegalArgumentException");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
     }
 
     /** test multiply */
+    @Test
     public void testMultiply() {
         OpenMapRealMatrix m = createSparseMatrix(testData);
         OpenMapRealMatrix mInv = createSparseMatrix(testDataInv);
@@ -204,7 +207,7 @@ public final class SparseRealMatrixTest 
                 entryTolerance);
         try {
             m.multiply(createSparseMatrix(bigSingular));
-            fail("Expecting illegalArgumentException");
+            Assert.fail("Expecting illegalArgumentException");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
@@ -216,6 +219,7 @@ public final class SparseRealMatrixTest 
     private double[][] d4 = new double[][] { { 1 }, { 2 }, { 3 }, { 4 } };
     private double[][] d5 = new double[][] { { 30 }, { 70 } };
 
+    @Test
     public void testMultiply2() {
         RealMatrix m3 = createSparseMatrix(d3);
         RealMatrix m4 = createSparseMatrix(d4);
@@ -224,19 +228,21 @@ public final class SparseRealMatrixTest 
     }
 
     /** test trace */
+    @Test
     public void testTrace() {
         RealMatrix m = createSparseMatrix(id);
-        assertEquals("identity trace", 3d, m.getTrace(), entryTolerance);
+        Assert.assertEquals("identity trace", 3d, m.getTrace(), entryTolerance);
         m = createSparseMatrix(testData2);
         try {
             m.getTrace();
-            fail("Expecting NonSquareMatrixException");
+            Assert.fail("Expecting NonSquareMatrixException");
         } catch (NonSquareMatrixException ex) {
             // ignored
         }
     }
 
     /** test sclarAdd */
+    @Test
     public void testScalarAdd() {
         RealMatrix m = createSparseMatrix(testData);
         assertClose("scalar add", createSparseMatrix(testDataPlus2),
@@ -244,6 +250,7 @@ public final class SparseRealMatrixTest 
     }
 
     /** test operate */
+    @Test
     public void testOperate() {
         RealMatrix m = createSparseMatrix(id);
         assertClose("identity operate", testVector, m.operate(testVector),
@@ -253,26 +260,27 @@ public final class SparseRealMatrixTest 
         m = createSparseMatrix(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 = createSparseMatrix(new double[][] {
                 { 1, 2 }, { 3, 4 }, { 5, 6 } });
         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 = createSparseMatrix(testData);
         RealMatrix mIT = new LUDecompositionImpl(m).getSolver().getInverse().transpose();
         RealMatrix mTI = new LUDecompositionImpl(m.transpose()).getSolver().getInverse();
@@ -283,6 +291,7 @@ public final class SparseRealMatrixTest 
     }
 
     /** test preMultiply by vector */
+    @Test
     public void testPremultiplyVector() {
         RealMatrix m = createSparseMatrix(testData);
         assertClose("premultiply", m.preMultiply(testVector), preMultTest,
@@ -292,12 +301,13 @@ public final class SparseRealMatrixTest 
         m = createSparseMatrix(bigSingular);
         try {
             m.preMultiply(testVector);
-            fail("expecting MathIllegalArgumentException");
+            Assert.fail("expecting MathIllegalArgumentException");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
     }
 
+    @Test
     public void testPremultiply() {
         RealMatrix m3 = createSparseMatrix(d3);
         RealMatrix m4 = createSparseMatrix(d4);
@@ -317,42 +327,45 @@ public final class SparseRealMatrixTest 
                 entryTolerance);
         try {
             m.preMultiply(createSparseMatrix(bigSingular));
-            fail("Expecting illegalArgumentException");
+            Assert.fail("Expecting illegalArgumentException");
         } catch (MathIllegalArgumentException ex) {
             // ignored
         }
     }
 
+    @Test
     public void testGetVectors() {
         RealMatrix m = createSparseMatrix(testData);
         assertClose("get row", m.getRow(0), testDataRow1, entryTolerance);
         assertClose("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 = createSparseMatrix(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 } };
@@ -362,12 +375,12 @@ public final class SparseRealMatrixTest 
         RealMatrix n = createSparseMatrix(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 },
@@ -375,16 +388,17 @@ public final class SparseRealMatrixTest 
         RealMatrix coefficients = createSparseMatrix(coefficientsData);
         double[] constants = { 1, -2, 1 };
         double[] solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants);
-        assertEquals(2 * solution[0] + 3 * solution[1] - 2 * solution[2],
+        Assert.assertEquals(2 * solution[0] + 3 * solution[1] - 2 * solution[2],
                 constants[0], 1E-12);
-        assertEquals(-1 * solution[0] + 7 * solution[1] + 6 * solution[2],
+        Assert.assertEquals(-1 * solution[0] + 7 * solution[1] + 6 * solution[2],
                 constants[1], 1E-12);
-        assertEquals(4 * solution[0] - 3 * solution[1] - 5 * solution[2],
+        Assert.assertEquals(4 * solution[0] - 3 * solution[1] - 5 * solution[2],
                 constants[2], 1E-12);
 
     }
 
     // test submatrix accessors
+    @Test
     public void testSubMatrix() {
         RealMatrix m = createSparseMatrix(subTestData);
         RealMatrix mRows23Cols00 = createSparseMatrix(subRows23Cols00);
@@ -395,135 +409,139 @@ public final class SparseRealMatrixTest 
         RealMatrix mRows03Cols123 = createSparseMatrix(subRows03Cols123);
         RealMatrix mRows20Cols123 = createSparseMatrix(subRows20Cols123);
         RealMatrix mRows31Cols31 = createSparseMatrix(subRows31Cols31);
-        assertEquals("Rows23Cols00", mRows23Cols00, m.getSubMatrix(2, 3, 0, 0));
-        assertEquals("Rows00Cols33", mRows00Cols33, m.getSubMatrix(0, 0, 3, 3));
-        assertEquals("Rows01Cols23", mRows01Cols23, m.getSubMatrix(0, 1, 2, 3));
-        assertEquals("Rows02Cols13", mRows02Cols13,
+        Assert.assertEquals("Rows23Cols00", mRows23Cols00, m.getSubMatrix(2, 3, 0, 0));
+        Assert.assertEquals("Rows00Cols33", mRows00Cols33, m.getSubMatrix(0, 0, 3, 3));
+        Assert.assertEquals("Rows01Cols23", mRows01Cols23, m.getSubMatrix(0, 1, 2, 3));
+        Assert.assertEquals("Rows02Cols13", mRows02Cols13,
             m.getSubMatrix(new int[] { 0, 2 }, new int[] { 1, 3 }));
-        assertEquals("Rows03Cols12", mRows03Cols12,
+        Assert.assertEquals("Rows03Cols12", mRows03Cols12,
             m.getSubMatrix(new int[] { 0, 3 }, new int[] { 1, 2 }));
-        assertEquals("Rows03Cols123", mRows03Cols123,
+        Assert.assertEquals("Rows03Cols123", mRows03Cols123,
             m.getSubMatrix(new int[] { 0, 3 }, new int[] { 1, 2, 3 }));
-        assertEquals("Rows20Cols123", mRows20Cols123,
+        Assert.assertEquals("Rows20Cols123", mRows20Cols123,
             m.getSubMatrix(new int[] { 2, 0 }, new int[] { 1, 2, 3 }));
-        assertEquals("Rows31Cols31", mRows31Cols31,
+        Assert.assertEquals("Rows31Cols31", mRows31Cols31,
             m.getSubMatrix(new int[] { 3, 1 }, new int[] { 3, 1 }));
-        assertEquals("Rows31Cols31", mRows31Cols31,
+        Assert.assertEquals("Rows31Cols31", mRows31Cols31,
             m.getSubMatrix(new int[] { 3, 1 }, new int[] { 3, 1 }));
 
         try {
             m.getSubMatrix(1, 0, 2, 4);
-            fail("Expecting NumberIsTooSmallException");
+            Assert.fail("Expecting NumberIsTooSmallException");
         } catch (NumberIsTooSmallException ex) {
             // expected
         }
         try {
             m.getSubMatrix(-1, 1, 2, 2);
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
         try {
             m.getSubMatrix(1, 0, 2, 2);
-            fail("Expecting NumberIsTooSmallException");
+            Assert.fail("Expecting NumberIsTooSmallException");
         } catch (NumberIsTooSmallException ex) {
             // expected
         }
         try {
             m.getSubMatrix(1, 0, 2, 4);
-            fail("Expecting NumberIsTooSmallException");
+            Assert.fail("Expecting NumberIsTooSmallException");
         } catch (NumberIsTooSmallException ex) {
             // expected
         }
         try {
             m.getSubMatrix(new int[] {}, new int[] { 0 });
-            fail("Expecting NoDataException");
+            Assert.fail("Expecting NoDataException");
         } catch (NoDataException ex) {
             // expected
         }
         try {
             m.getSubMatrix(new int[] { 0 }, new int[] { 4 });
-            fail("Expecting OutOfRangeException");
+            Assert.fail("Expecting OutOfRangeException");
         } catch (OutOfRangeException ex) {
             // expected
         }
     }
 
+    @Test
     public void testGetRowMatrix() {
         RealMatrix m = createSparseMatrix(subTestData);
         RealMatrix mRow0 = createSparseMatrix(subRow0);
         RealMatrix mRow3 = createSparseMatrix(subRow3);
-        assertEquals("Row0", mRow0, m.getRowMatrix(0));
-        assertEquals("Row3", mRow3, m.getRowMatrix(3));
+        Assert.assertEquals("Row0", mRow0, m.getRowMatrix(0));
+        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 testGetColumnMatrix() {
         RealMatrix m = createSparseMatrix(subTestData);
         RealMatrix mColumn1 = createSparseMatrix(subColumn1);
         RealMatrix mColumn3 = createSparseMatrix(subColumn3);
-        assertEquals("Column1", mColumn1, m.getColumnMatrix(1));
-        assertEquals("Column3", mColumn3, m.getColumnMatrix(3));
+        Assert.assertEquals("Column1", mColumn1, m.getColumnMatrix(1));
+        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 testGetRowVector() {
         RealMatrix m = createSparseMatrix(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 testGetColumnVector() {
         RealMatrix m = createSparseMatrix(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
         }
@@ -537,43 +555,46 @@ public final class SparseRealMatrixTest 
         return new ArrayRealVector(data, false);
     }
 
+    @Test
     public void testEqualsAndHashCode() {
         OpenMapRealMatrix m = createSparseMatrix(testData);
         OpenMapRealMatrix m1 = m.copy();
         OpenMapRealMatrix mt = (OpenMapRealMatrix) 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(createSparseMatrix(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(createSparseMatrix(bigSingular)));
     }
 
+    @Test
     public void testToString() {
         OpenMapRealMatrix m = createSparseMatrix(testData);
-        assertEquals("OpenMapRealMatrix{{1.0,2.0,3.0},{2.0,5.0,3.0},{1.0,0.0,8.0}}",
+        Assert.assertEquals("OpenMapRealMatrix{{1.0,2.0,3.0},{2.0,5.0,3.0},{1.0,0.0,8.0}}",
             m.toString());
         m = new OpenMapRealMatrix(1, 1);
-        assertEquals("OpenMapRealMatrix{{0.0}}", m.toString());
+        Assert.assertEquals("OpenMapRealMatrix{{0.0}}", m.toString());
     }
 
-    public void testSetSubMatrix() throws Exception {
+    @Test
+    public void testSetSubMatrix() {
         OpenMapRealMatrix m = createSparseMatrix(testData);
         m.setSubMatrix(detData2, 1, 1);
         RealMatrix expected = createSparseMatrix(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 = createSparseMatrix(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 = createSparseMatrix(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);
 
         // javadoc example
         OpenMapRealMatrix matrix =
@@ -582,25 +603,25 @@ public final class SparseRealMatrixTest 
         matrix.setSubMatrix(new double[][] { { 3, 4 }, { 5, 6 } }, 1, 1);
         expected = createSparseMatrix(new double[][] {
                 { 1, 2, 3, 4 }, { 5, 3, 4, 8 }, { 9, 5, 6, 2 } });
-        assertEquals(expected, matrix);
+        Assert.assertEquals(expected, matrix);
 
         // 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
         }
@@ -608,13 +629,13 @@ public final class SparseRealMatrixTest 
         // null
         try {
             m.setSubMatrix(null, 1, 1);
-            fail("expecting NullPointerException");
+            Assert.fail("expecting NullPointerException");
         } catch (NullPointerException e) {
             // expected
         }
         try {
             new OpenMapRealMatrix(0, 0);
-            fail("expecting MathIllegalArgumentException");
+            Assert.fail("expecting MathIllegalArgumentException");
         } catch (MathIllegalArgumentException e) {
             // expected
         }
@@ -622,7 +643,7 @@ public final class SparseRealMatrixTest 
         // ragged
         try {
             m.setSubMatrix(new double[][] { { 1 }, { 2, 3 } }, 0, 0);
-            fail("expecting MathIllegalArgumentException");
+            Assert.fail("expecting MathIllegalArgumentException");
         } catch (MathIllegalArgumentException e) {
             // expected
         }
@@ -630,16 +651,17 @@ public final class SparseRealMatrixTest 
         // empty
         try {
             m.setSubMatrix(new double[][] { {} }, 0, 0);
-            fail("expecting MathIllegalArgumentException");
+            Assert.fail("expecting MathIllegalArgumentException");
         } catch (MathIllegalArgumentException e) {
             // expected
         }
 
     }
 
+    @Test
     public void testSerial()  {
         OpenMapRealMatrix m = createSparseMatrix(testData);
-        assertEquals(m,TestUtils.serializeAndRecover(m));
+        Assert.assertEquals(m,TestUtils.serializeAndRecover(m));
     }
 
     // --------------- -----------------Protected methods
@@ -647,17 +669,17 @@ public final class SparseRealMatrixTest 
     /** verifies that two matrices are close (1-norm) */
     protected void assertClose(String msg, RealMatrix m, RealMatrix n,
             double tolerance) {
-        assertTrue(msg, m.subtract(n).getNorm() < tolerance);
+        Assert.assertTrue(msg, m.subtract(n).getNorm() < tolerance);
     }
 
     /** verifies that two vectors are close (sup norm) */
     protected void assertClose(String msg, double[] m, double[] n,
             double tolerance) {
         if (m.length != n.length) {
-            fail("vectors not same length");
+            Assert.fail("vectors not same length");
         }
         for (int i = 0; i < m.length; i++) {
-            assertEquals(msg + " " + i + " elements differ", m[i], n[i],
+            Assert.assertEquals(msg + " " + i + " elements differ", m[i], n[i],
                     tolerance);
         }
     }
@@ -671,6 +693,4 @@ public final class SparseRealMatrixTest 
         }
         return matrix;
     }
-
-
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/TriDiagonalTransformerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/TriDiagonalTransformerTest.java?rev=1079350&r1=1079349&r2=1079350&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/TriDiagonalTransformerTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/TriDiagonalTransformerTest.java Tue Mar  8 13:42:16 2011
@@ -20,11 +20,11 @@ package org.apache.commons.math.linear;
 import java.util.Arrays;
 
 import org.apache.commons.math.util.FastMath;
-import org.apache.commons.math.exception.NonSquareMatrixException;
 
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.Assert;
 
-public class TriDiagonalTransformerTest extends TestCase {
+public class TriDiagonalTransformerTest {
 
     private double[][] testSquare5 = {
             { 1, 2, 3, 1, 1 },
@@ -40,19 +40,17 @@ public class TriDiagonalTransformerTest 
             { 4, 2, 0 }
     };
 
-    public TriDiagonalTransformerTest(String name) {
-        super(name);
-    }
-
+    @Test
     public void testNonSquare() {
         try {
             new TriDiagonalTransformer(MatrixUtils.createRealMatrix(new double[3][2]));
-            fail("an exception should have been thrown");
+            Assert.fail("an exception should have been thrown");
         } catch (NonSquareMatrixException ime) {
             // expected behavior
         }
     }
 
+    @Test
     public void testAEqualQTQt() {
         checkAEqualQTQt(MatrixUtils.createRealMatrix(testSquare5));
         checkAEqualQTQt(MatrixUtils.createRealMatrix(testSquare3));
@@ -64,9 +62,10 @@ public class TriDiagonalTransformerTest 
         RealMatrix qT = transformer.getQT();
         RealMatrix t  = transformer.getT();
         double norm = q.multiply(t).multiply(qT).subtract(matrix).getNorm();
-        assertEquals(0, norm, 4.0e-15);
+        Assert.assertEquals(0, norm, 4.0e-15);
     }
 
+    @Test
     public void testNoAccessBelowDiagonal() {
         checkNoAccessBelowDiagonal(testSquare5);
         checkNoAccessBelowDiagonal(testSquare3);
@@ -84,14 +83,16 @@ public class TriDiagonalTransformerTest 
         RealMatrix qT = transformer.getQT();
         RealMatrix t  = transformer.getT();
         double norm = q.multiply(t).multiply(qT).subtract(MatrixUtils.createRealMatrix(data)).getNorm();
-        assertEquals(0, norm, 4.0e-15);
+        Assert.assertEquals(0, norm, 4.0e-15);
     }
 
+    @Test
     public void testQOrthogonal() {
         checkOrthogonal(new TriDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare5)).getQ());
         checkOrthogonal(new TriDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare3)).getQ());
     }
 
+    @Test
     public void testQTOrthogonal() {
         checkOrthogonal(new TriDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare5)).getQT());
         checkOrthogonal(new TriDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare3)).getQT());
@@ -100,9 +101,10 @@ public class TriDiagonalTransformerTest 
     private void checkOrthogonal(RealMatrix m) {
         RealMatrix mTm = m.transpose().multiply(m);
         RealMatrix id  = MatrixUtils.createRealIdentityMatrix(mTm.getRowDimension());
-        assertEquals(0, mTm.subtract(id).getNorm(), 1.0e-15);
+        Assert.assertEquals(0, mTm.subtract(id).getNorm(), 1.0e-15);
     }
 
+    @Test
     public void testTTriDiagonal() {
         checkTriDiagonal(new TriDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare5)).getT());
         checkTriDiagonal(new TriDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare3)).getT());
@@ -114,12 +116,13 @@ public class TriDiagonalTransformerTest 
         for (int i = 0; i < rows; ++i) {
             for (int j = 0; j < cols; ++j) {
                 if ((i < j - 1) || (i > j + 1)) {
-                    assertEquals(0, m.getEntry(i, j), 1.0e-16);
+                    Assert.assertEquals(0, m.getEntry(i, j), 1.0e-16);
                 }
             }
         }
     }
 
+    @Test
     public void testMatricesValues5() {
         checkMatricesValues(testSquare5,
                             new double[][] {
@@ -133,6 +136,7 @@ public class TriDiagonalTransformerTest 
                             new double[] { -FastMath.sqrt(15), -3.0832882879592476, 0.6082710842351517, 1.1786086405912128 });
     }
 
+    @Test
     public void testMatricesValues3() {
         checkMatricesValues(testSquare3,
                             new double[][] {
@@ -152,7 +156,7 @@ public class TriDiagonalTransformerTest 
 
         // check values against known references
         RealMatrix q = transformer.getQ();
-        assertEquals(0, q.subtract(MatrixUtils.createRealMatrix(qRef)).getNorm(), 1.0e-14);
+        Assert.assertEquals(0, q.subtract(MatrixUtils.createRealMatrix(qRef)).getNorm(), 1.0e-14);
 
         RealMatrix t = transformer.getT();
         double[][] tData = new double[mainDiagnonal.length][mainDiagnonal.length];
@@ -165,12 +169,10 @@ public class TriDiagonalTransformerTest 
                 tData[i][i + 1] = secondaryDiagonal[i];
             }
         }
-        assertEquals(0, t.subtract(MatrixUtils.createRealMatrix(tData)).getNorm(), 1.0e-14);
+        Assert.assertEquals(0, t.subtract(MatrixUtils.createRealMatrix(tData)).getNorm(), 1.0e-14);
 
         // check the same cached instance is returned the second time
-        assertTrue(q == transformer.getQ());
-        assertTrue(t == transformer.getT());
-
+        Assert.assertTrue(q == transformer.getQ());
+        Assert.assertTrue(t == transformer.getT());
     }
-
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java?rev=1079350&r1=1079349&r2=1079350&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java Tue Mar  8 13:42:16 2011
@@ -25,7 +25,6 @@ import java.util.List;
 
 import junit.framework.TestCase;
 
-import org.apache.commons.math.exception.SingularMatrixException;
 import org.apache.commons.math.exception.ConvergenceException;
 import org.apache.commons.math.exception.DimensionMismatchException;
 import org.apache.commons.math.exception.TooManyEvaluationsException;
@@ -34,6 +33,7 @@ import org.apache.commons.math.analysis.
 import org.apache.commons.math.analysis.MultivariateMatrixFunction;
 import org.apache.commons.math.linear.BlockRealMatrix;
 import org.apache.commons.math.linear.RealMatrix;
+import org.apache.commons.math.linear.SingularMatrixException;
 import org.apache.commons.math.optimization.SimpleVectorialValueChecker;
 import org.apache.commons.math.optimization.VectorialPointValuePair;
 import org.apache.commons.math.util.MathUtils;



Mime
View raw message