diff --git a/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java b/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java
index 7903524ca..7aea5a962 100644
--- a/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java
+++ b/src/main/java/org/apache/commons/math/linear/AbstractFieldMatrix.java
@@ -22,8 +22,6 @@ import java.util.Arrays;
import org.apache.commons.math.Field;
import org.apache.commons.math.FieldElement;
-import org.apache.commons.math.exception.MatrixDimensionMismatchException;
-import org.apache.commons.math.exception.NonSquareMatrixException;
import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.exception.NoDataException;
import org.apache.commons.math.exception.OutOfRangeException;
diff --git a/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java b/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java
index 1c45990a7..bdc296173 100644
--- a/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java
+++ b/src/main/java/org/apache/commons/math/linear/AbstractRealMatrix.java
@@ -20,8 +20,6 @@ package org.apache.commons.math.linear;
import org.apache.commons.math.exception.NoDataException;
import org.apache.commons.math.exception.NotStrictlyPositiveException;
import org.apache.commons.math.exception.DimensionMismatchException;
-import org.apache.commons.math.exception.NonSquareMatrixException;
-import org.apache.commons.math.exception.MatrixDimensionMismatchException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.util.MathUtils;
import org.apache.commons.math.util.FastMath;
diff --git a/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java b/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java
index ac9a655eb..d93fd6181 100644
--- a/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java
+++ b/src/main/java/org/apache/commons/math/linear/Array2DRowFieldMatrix.java
@@ -162,7 +162,7 @@ public class Array2DRowFieldMatrix>
*
* @param m Matrix to be added.
* @return {@code this} + m.
- * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
+ * @throws MatrixDimensionMismatchException
* if {@code m} is not the same size as this matrix.
*/
public Array2DRowFieldMatrix add(final Array2DRowFieldMatrix m) {
@@ -189,7 +189,7 @@ public class Array2DRowFieldMatrix>
*
* @param m Matrix to be subtracted.
* @return {@code this} + m.
- * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
+ * @throws MatrixDimensionMismatchException
* if {@code m} is not the same size as this matrix.
*/
public Array2DRowFieldMatrix subtract(final Array2DRowFieldMatrix m) {
diff --git a/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java b/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java
index db61eab24..d0a1cf6ba 100644
--- a/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java
+++ b/src/main/java/org/apache/commons/math/linear/Array2DRowRealMatrix.java
@@ -168,7 +168,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
*
* @param m Matrix to be added.
* @return {@code this} + m.
- * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
+ * @throws MatrixDimensionMismatchException
* if {@code m} is not the same size as this matrix.
*/
public Array2DRowRealMatrix add(final Array2DRowRealMatrix m) {
@@ -195,7 +195,7 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ
*
* @param m Matrix to be subtracted.
* @return {@code this} - m.
- * @throws org.apache.commons.math.exception.MatrixDimensionMismatchException
+ * @throws MatrixDimensionMismatchException
* if {@code m} is not the same size as this matrix.
*/
public Array2DRowRealMatrix subtract(final Array2DRowRealMatrix m) {
diff --git a/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java b/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java
index d59ab69fb..b90b6d00a 100644
--- a/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java
+++ b/src/main/java/org/apache/commons/math/linear/BlockFieldMatrix.java
@@ -23,7 +23,6 @@ import org.apache.commons.math.Field;
import org.apache.commons.math.FieldElement;
import org.apache.commons.math.exception.NoDataException;
import org.apache.commons.math.exception.DimensionMismatchException;
-import org.apache.commons.math.exception.MatrixDimensionMismatchException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.util.FastMath;
diff --git a/src/main/java/org/apache/commons/math/linear/BlockRealMatrix.java b/src/main/java/org/apache/commons/math/linear/BlockRealMatrix.java
index ca6a0f109..9a53cb66a 100644
--- a/src/main/java/org/apache/commons/math/linear/BlockRealMatrix.java
+++ b/src/main/java/org/apache/commons/math/linear/BlockRealMatrix.java
@@ -20,7 +20,6 @@ package org.apache.commons.math.linear;
import java.io.Serializable;
import java.util.Arrays;
-import org.apache.commons.math.exception.MatrixDimensionMismatchException;
import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.exception.NoDataException;
import org.apache.commons.math.exception.util.LocalizedFormats;
diff --git a/src/main/java/org/apache/commons/math/linear/CholeskyDecomposition.java b/src/main/java/org/apache/commons/math/linear/CholeskyDecomposition.java
index ff62370ac..c45c5e378 100644
--- a/src/main/java/org/apache/commons/math/linear/CholeskyDecomposition.java
+++ b/src/main/java/org/apache/commons/math/linear/CholeskyDecomposition.java
@@ -27,8 +27,7 @@ package org.apache.commons.math.linear;
*
*
* @param matrix Symmetrical matrix to transform.
- * @exception NonSquareMatrixException if the matrix is not square.
+ * @throws NonSquareMatrixException if the matrix is not square.
*/
public TriDiagonalTransformer(RealMatrix matrix) {
if (!matrix.isSquare()) {
- throw new NonSquareMatrixException(matrix.getRowDimension(), matrix.getColumnDimension());
+ throw new NonSquareMatrixException(matrix.getRowDimension(),
+ matrix.getColumnDimension());
}
final int m = matrix.getRowDimension();
diff --git a/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java b/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java
index 1d11b4d7b..a89b3aed0 100644
--- a/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java
+++ b/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java
@@ -172,10 +172,10 @@ public abstract class AbstractLeastSquaresOptimizer
* Get the covariance matrix of the optimized parameters.
*
* @return the covariance matrix.
- * @throws org.apache.commons.math.exception.SingularMatrixException
+ * @throws org.apache.commons.math.linear.SingularMatrixException
* if the covariance matrix cannot be computed (singular problem).
- * @throws org.apache.commons.math.exception.MathUserException if the jacobian
- * function throws one.
+ * @throws org.apache.commons.math.exception.MathUserException if the
+ * jacobian function throws one.
*/
public double[][] getCovariances() {
// set up the jacobian
@@ -205,8 +205,8 @@ public abstract class AbstractLeastSquaresOptimizer
* Guessing is covariance-based: It only gives a rough order of magnitude.
*
* @return errors in optimized parameters
- * @throws org.apache.commons.math.exception.SingularMatrixException if
- * the covariances matrix cannot be computed.
+ * @throws org.apache.commons.math.linear.SingularMatrixException
+ * if the covariances matrix cannot be computed.
* @throws NumberIsTooSmallException if the number of degrees of freedom is not
* positive, i.e. the number of measurements is less or equal to the number of
* parameters.
diff --git a/src/main/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java b/src/main/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java
index 8d3a1e1ce..3c9c729d8 100644
--- a/src/main/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java
+++ b/src/main/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java
@@ -18,7 +18,6 @@
package org.apache.commons.math.optimization.general;
import org.apache.commons.math.exception.MathUserException;
-import org.apache.commons.math.exception.SingularMatrixException;
import org.apache.commons.math.exception.ConvergenceException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.linear.BlockRealMatrix;
@@ -26,6 +25,7 @@ import org.apache.commons.math.linear.DecompositionSolver;
import org.apache.commons.math.linear.LUDecompositionImpl;
import org.apache.commons.math.linear.QRDecompositionImpl;
import org.apache.commons.math.linear.RealMatrix;
+import org.apache.commons.math.linear.SingularMatrixException;
import org.apache.commons.math.optimization.VectorialPointValuePair;
import org.apache.commons.math.optimization.ConvergenceChecker;
diff --git a/src/main/java/org/apache/commons/math/random/CorrelatedRandomVectorGenerator.java b/src/main/java/org/apache/commons/math/random/CorrelatedRandomVectorGenerator.java
index 7de1a0b19..264bfd296 100644
--- a/src/main/java/org/apache/commons/math/random/CorrelatedRandomVectorGenerator.java
+++ b/src/main/java/org/apache/commons/math/random/CorrelatedRandomVectorGenerator.java
@@ -18,7 +18,7 @@
package org.apache.commons.math.random;
import org.apache.commons.math.exception.DimensionMismatchException;
-import org.apache.commons.math.exception.NonPositiveDefiniteMatrixException;
+import org.apache.commons.math.linear.NonPositiveDefiniteMatrixException;
import org.apache.commons.math.linear.MatrixUtils;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.util.FastMath;
@@ -73,17 +73,18 @@ public class CorrelatedRandomVectorGenerator
/** Rank of the covariance matrix. */
private int rank;
- /** Simple constructor.
- * Build a correlated random vector generator from its mean
- * vector and covariance matrix.
- * @param mean expected mean values for all components
- * @param covariance covariance matrix
- * @param small diagonal elements threshold under which column are
+ /**
+ * Builds a correlated random vector generator from its mean
+ * vector and covariance matrix.
+ *
+ * @param mean Expected mean values for all components.
+ * @param covariance Covariance matrix.
+ * @param small Diagonal elements threshold under which column are
* considered to be dependent on previous ones and are discarded
* @param generator underlying generator for uncorrelated normalized
- * components
- * @throws NonPositiveDefiniteMatrixException if the
- * covariance matrix is not strictly positive definite
+ * components.
+ * @throws org.apache.commons.math.linear.NonPositiveDefiniteMatrixException
+ * if the covariance matrix is not strictly positive definite.
* @throws DimensionMismatchException if the mean and covariance
* arrays dimensions do not match.
*/
@@ -100,19 +101,19 @@ public class CorrelatedRandomVectorGenerator
this.generator = generator;
normalized = new double[rank];
-
}
- /** Simple constructor.
- * Build a null mean random correlated vector generator from its
- * covariance matrix.
- * @param covariance covariance matrix
- * @param small diagonal elements threshold under which column are
- * considered to be dependent on previous ones and are discarded
- * @param generator underlying generator for uncorrelated normalized
- * components
- * @exception NonPositiveDefiniteMatrixException if the
- * covariance matrix is not strictly positive definite
+ /**
+ * Builds a null mean random correlated vector generator from its
+ * covariance matrix.
+ *
+ * @param covariance Covariance matrix.
+ * @param small Diagonal elements threshold under which column are
+ * considered to be dependent on previous ones and are discarded.
+ * @param generator Underlying generator for uncorrelated normalized
+ * components.
+ * @throws org.apache.commons.math.linear.NonPositiveDefiniteMatrixException
+ * if the covariance matrix is not strictly positive definite.
*/
public CorrelatedRandomVectorGenerator(RealMatrix covariance, double small,
NormalizedRandomGenerator generator) {
@@ -126,7 +127,6 @@ public class CorrelatedRandomVectorGenerator
this.generator = generator;
normalized = new double[rank];
-
}
/** Get the underlying normalized components generator.
@@ -171,8 +171,8 @@ public class CorrelatedRandomVectorGenerator
* @param covariance covariance matrix
* @param small diagonal elements threshold under which column are
* considered to be dependent on previous ones and are discarded
- * @throws NonPositiveDefiniteMatrixException if the
- * covariance matrix is not strictly positive definite.
+ * @throws org.apache.commons.math.linear.NonPositiveDefiniteMatrixException
+ * if the covariance matrix is not strictly positive definite.
*/
private void decompose(RealMatrix covariance, double small) {
int order = covariance.getRowDimension();
diff --git a/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java b/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java
index de1df589c..4e2394acf 100644
--- a/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java
+++ b/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java
@@ -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.MathIllegalStateException;
* @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 Array2DRowRealMatrixTest extends TestCase {
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 Array2DRowRealMatrixTest extends TestCase {
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 Array2DRowRealMatrixTest extends TestCase {
}
/** 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 Array2DRowRealMatrixTest extends TestCase {
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 Array2DRowRealMatrixTest extends TestCase {
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 Array2DRowRealMatrixTest extends TestCase {
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 Array2DRowRealMatrixTest extends TestCase {
}
/** 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 Array2DRowRealMatrixTest extends TestCase {
}
/** test operate */
+ @Test
public void testOperate() {
RealMatrix m = new Array2DRowRealMatrix(id);
TestUtils.assertEquals("identity operate", testVector,
@@ -248,25 +255,27 @@ public final class Array2DRowRealMatrixTest extends TestCase {
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 Array2DRowRealMatrixTest extends TestCase {
}
/** 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 Array2DRowRealMatrixTest extends TestCase {
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 Array2DRowRealMatrixTest extends TestCase {
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 Array2DRowRealMatrixTest extends TestCase {
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 Array2DRowRealMatrixTest extends TestCase {
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 Array2DRowRealMatrixTest extends TestCase {
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 Array2DRowRealMatrixTest extends TestCase {
}
}
+ @Test
public void testCopySubMatrix() {
RealMatrix m = new Array2DRowRealMatrix(subTestData);
checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0, false);
@@ -471,9 +487,9 @@ public final class Array2DRowRealMatrixTest extends TestCase {
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 Array2DRowRealMatrixTest extends TestCase {
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 Array2DRowRealMatrixTest extends TestCase {
}
}
+ @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 Array2DRowRealMatrixTest extends TestCase {
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 Array2DRowRealMatrixTest extends TestCase {
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 Array2DRowRealMatrixTest extends TestCase {
}
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 Array2DRowRealMatrixTest extends TestCase {
// 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 Array2DRowRealMatrixTest extends TestCase {
// 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 Array2DRowRealMatrixTest extends TestCase {
// 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 Array2DRowRealMatrixTest extends TestCase {
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 Array2DRowRealMatrixTest extends TestCase {
@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;
diff --git a/src/test/java/org/apache/commons/math/linear/BlockFieldMatrixTest.java b/src/test/java/org/apache/commons/math/linear/BlockFieldMatrixTest.java
index 98b1f7b33..a91c04ee1 100644
--- a/src/test/java/org/apache/commons/math/linear/BlockFieldMatrixTest.java
+++ b/src/test/java/org/apache/commons/math/linear/BlockFieldMatrixTest.java
@@ -19,18 +19,17 @@ package org.apache.commons.math.linear;
import java.util.Arrays;
import java.util.Random;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.Assert;
import org.apache.commons.math.TestUtils;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.fraction.Fraction;
import org.apache.commons.math.fraction.FractionField;
-import org.apache.commons.math.exception.MatrixDimensionMismatchException;
import org.apache.commons.math.exception.NoDataException;
import org.apache.commons.math.exception.OutOfRangeException;
import org.apache.commons.math.exception.NumberIsTooSmallException;
import org.apache.commons.math.exception.NotStrictlyPositiveException;
-import org.apache.commons.math.exception.NonSquareMatrixException;
import org.apache.commons.math.exception.MathIllegalArgumentException;
/**
@@ -39,7 +38,7 @@ import org.apache.commons.math.exception.MathIllegalArgumentException;
* @version $Revision$ $Date$
*/
-public final class BlockFieldMatrixTest extends TestCase {
+public final class BlockFieldMatrixTest {
// 3 x 3 identity matrix
protected Fraction[][] id = {
@@ -158,34 +157,33 @@ public final class BlockFieldMatrixTest extends TestCase {
protected double entryTolerance = 10E-16;
protected double normTolerance = 10E-14;
- public BlockFieldMatrixTest(String name) {
- super(name);
- }
-
/** test dimensions */
+ @Test
public void testDimensions() {
BlockFieldMatrix m = new BlockFieldMatrix(testData);
BlockFieldMatrix m2 = new BlockFieldMatrix(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() {
Random r = new Random(66636328996002l);
BlockFieldMatrix m1 = createRandomMatrix(r, 47, 83);
BlockFieldMatrix m2 = new BlockFieldMatrix(m1.getData());
- assertEquals(m1, m2);
+ Assert.assertEquals(m1, m2);
BlockFieldMatrix m3 = new BlockFieldMatrix(testData);
BlockFieldMatrix m4 = new BlockFieldMatrix(m3.getData());
- assertEquals(m3, m4);
+ Assert.assertEquals(m3, m4);
}
/** test add */
+ @Test
public void testAdd() {
BlockFieldMatrix m = new BlockFieldMatrix(testData);
BlockFieldMatrix mInv = new BlockFieldMatrix(testDataInv);
@@ -193,38 +191,41 @@ public final class BlockFieldMatrixTest extends TestCase {
Fraction[][] sumEntries = mPlusMInv.getData();
for (int row = 0; row < m.getRowDimension(); row++) {
for (int col = 0; col < m.getColumnDimension(); col++) {
- assertEquals(testDataPlusInv[row][col],sumEntries[row][col]);
+ Assert.assertEquals(testDataPlusInv[row][col],sumEntries[row][col]);
}
}
}
/** test add failure */
+ @Test
public void testAddFail() {
BlockFieldMatrix m = new BlockFieldMatrix(testData);
BlockFieldMatrix m2 = new BlockFieldMatrix(testData2);
try {
m.add(m2);
- fail("MathIllegalArgumentException expected");
+ Assert.fail("MathIllegalArgumentException expected");
} catch (MathIllegalArgumentException ex) {
// ignored
}
}
/** test m-n = m + -n */
+ @Test
public void testPlusMinus() {
BlockFieldMatrix m = new BlockFieldMatrix(testData);
BlockFieldMatrix m2 = new BlockFieldMatrix(testDataInv);
TestUtils.assertEquals(m.subtract(m2), m2.scalarMultiply(new Fraction(-1)).add(m));
try {
m.subtract(new BlockFieldMatrix(testData2));
- fail("Expecting illegalArgumentException");
+ Assert.fail("Expecting illegalArgumentException");
} catch (MathIllegalArgumentException ex) {
// ignored
}
}
/** test multiply */
- public void testMultiply() {
+ @Test
+ public void testMultiply() {
BlockFieldMatrix m = new BlockFieldMatrix(testData);
BlockFieldMatrix mInv = new BlockFieldMatrix(testDataInv);
BlockFieldMatrix identity = new BlockFieldMatrix(id);
@@ -236,14 +237,14 @@ public final class BlockFieldMatrixTest extends TestCase {
TestUtils.assertEquals(m2.multiply(identity), m2);
try {
m.multiply(new BlockFieldMatrix(bigSingular));
- fail("Expecting illegalArgumentException");
+ Assert.fail("Expecting illegalArgumentException");
} catch (MathIllegalArgumentException ex) {
// expected
}
}
+ @Test
public void testSeveralBlocks() {
-
FieldMatrix m =
new BlockFieldMatrix(FractionField.getInstance(), 37, 41);
for (int i = 0; i < m.getRowDimension(); ++i) {
@@ -253,25 +254,25 @@ public final class BlockFieldMatrixTest extends TestCase {
}
FieldMatrix mT = m.transpose();
- assertEquals(m.getRowDimension(), mT.getColumnDimension());
- assertEquals(m.getColumnDimension(), mT.getRowDimension());
+ Assert.assertEquals(m.getRowDimension(), mT.getColumnDimension());
+ Assert.assertEquals(m.getColumnDimension(), mT.getRowDimension());
for (int i = 0; i < mT.getRowDimension(); ++i) {
for (int j = 0; j < mT.getColumnDimension(); ++j) {
- assertEquals(m.getEntry(j, i), mT.getEntry(i, j));
+ Assert.assertEquals(m.getEntry(j, i), mT.getEntry(i, j));
}
}
FieldMatrix mPm = m.add(m);
for (int i = 0; i < mPm.getRowDimension(); ++i) {
for (int j = 0; j < mPm.getColumnDimension(); ++j) {
- assertEquals(m.getEntry(i, j).multiply(new Fraction(2)), mPm.getEntry(i, j));
+ Assert.assertEquals(m.getEntry(i, j).multiply(new Fraction(2)), mPm.getEntry(i, j));
}
}
FieldMatrix mPmMm = mPm.subtract(m);
for (int i = 0; i < mPmMm.getRowDimension(); ++i) {
for (int j = 0; j < mPmMm.getColumnDimension(); ++j) {
- assertEquals(m.getEntry(i, j), mPmMm.getEntry(i, j));
+ Assert.assertEquals(m.getEntry(i, j), mPmMm.getEntry(i, j));
}
}
@@ -282,7 +283,7 @@ public final class BlockFieldMatrixTest extends TestCase {
for (int k = 0; k < mT.getColumnDimension(); ++k) {
sum = sum.add(new Fraction(k * 11 + i, 11).multiply(new Fraction(k * 11 + j, 11)));
}
- assertEquals(sum, mTm.getEntry(i, j));
+ Assert.assertEquals(sum, mTm.getEntry(i, j));
}
}
@@ -293,35 +294,35 @@ public final class BlockFieldMatrixTest extends TestCase {
for (int k = 0; k < m.getColumnDimension(); ++k) {
sum = sum.add(new Fraction(i * 11 + k, 11).multiply(new Fraction(j * 11 + k, 11)));
}
- assertEquals(sum, mmT.getEntry(i, j));
+ Assert.assertEquals(sum, mmT.getEntry(i, j));
}
}
FieldMatrix sub1 = m.getSubMatrix(2, 9, 5, 20);
for (int i = 0; i < sub1.getRowDimension(); ++i) {
for (int j = 0; j < sub1.getColumnDimension(); ++j) {
- assertEquals(new Fraction((i + 2) * 11 + (j + 5), 11), sub1.getEntry(i, j));
+ Assert.assertEquals(new Fraction((i + 2) * 11 + (j + 5), 11), sub1.getEntry(i, j));
}
}
FieldMatrix sub2 = m.getSubMatrix(10, 12, 3, 40);
for (int i = 0; i < sub2.getRowDimension(); ++i) {
for (int j = 0; j < sub2.getColumnDimension(); ++j) {
- assertEquals(new Fraction((i + 10) * 11 + (j + 3), 11), sub2.getEntry(i, j));
+ Assert.assertEquals(new Fraction((i + 10) * 11 + (j + 3), 11), sub2.getEntry(i, j));
}
}
FieldMatrix sub3 = m.getSubMatrix(30, 34, 0, 5);
for (int i = 0; i < sub3.getRowDimension(); ++i) {
for (int j = 0; j < sub3.getColumnDimension(); ++j) {
- assertEquals(new Fraction((i + 30) * 11 + (j + 0), 11), sub3.getEntry(i, j));
+ Assert.assertEquals(new Fraction((i + 30) * 11 + (j + 0), 11), sub3.getEntry(i, j));
}
}
FieldMatrix sub4 = m.getSubMatrix(30, 32, 32, 35);
for (int i = 0; i < sub4.getRowDimension(); ++i) {
for (int j = 0; j < sub4.getColumnDimension(); ++j) {
- assertEquals(new Fraction((i + 30) * 11 + (j + 32), 11), sub4.getEntry(i, j));
+ Assert.assertEquals(new Fraction((i + 30) * 11 + (j + 32), 11), sub4.getEntry(i, j));
}
}
@@ -341,6 +342,7 @@ public final class BlockFieldMatrixTest extends TestCase {
};
private Fraction[][] d5 = new Fraction[][] {{new Fraction(30)},{new Fraction(70)}};
+ @Test
public void testMultiply2() {
FieldMatrix m3 = new BlockFieldMatrix(d3);
FieldMatrix m4 = new BlockFieldMatrix(d4);
@@ -349,19 +351,21 @@ public final class BlockFieldMatrixTest extends TestCase {
}
/** test trace */
+ @Test
public void testTrace() {
FieldMatrix m = new BlockFieldMatrix(id);
- assertEquals(new Fraction(3),m.getTrace());
+ Assert.assertEquals(new Fraction(3),m.getTrace());
m = new BlockFieldMatrix(testData2);
try {
m.getTrace();
- fail("Expecting NonSquareMatrixException");
+ Assert.fail("Expecting NonSquareMatrixException");
} catch (NonSquareMatrixException ex) {
// ignored
}
}
/** test scalarAdd */
+ @Test
public void testScalarAdd() {
FieldMatrix m = new BlockFieldMatrix(testData);
TestUtils.assertEquals(new BlockFieldMatrix(testDataPlus2),
@@ -369,6 +373,7 @@ public final class BlockFieldMatrixTest extends TestCase {
}
/** test operate */
+ @Test
public void testOperate() {
FieldMatrix m = new BlockFieldMatrix(id);
TestUtils.assertEquals(testVector, m.operate(testVector));
@@ -376,12 +381,13 @@ public final class BlockFieldMatrixTest extends TestCase {
m = new BlockFieldMatrix(bigSingular);
try {
m.operate(testVector);
- fail("Expecting illegalArgumentException");
+ Assert.fail("Expecting illegalArgumentException");
} catch (MathIllegalArgumentException ex) {
// ignored
}
}
+ @Test
public void testOperateLarge() {
int p = (11 * BlockFieldMatrix.BLOCK_SIZE) / 10;
int q = (11 * BlockFieldMatrix.BLOCK_SIZE) / 10;
@@ -395,6 +401,7 @@ public final class BlockFieldMatrixTest extends TestCase {
}
}
+ @Test
public void testOperatePremultiplyLarge() {
int p = (11 * BlockFieldMatrix.BLOCK_SIZE) / 10;
int q = (11 * BlockFieldMatrix.BLOCK_SIZE) / 10;
@@ -409,6 +416,7 @@ public final class BlockFieldMatrixTest extends TestCase {
}
/** test issue MATH-209 */
+ @Test
public void testMath209() {
FieldMatrix a = new BlockFieldMatrix(new Fraction[][] {
{ new Fraction(1), new Fraction(2) },
@@ -416,13 +424,14 @@ public final class BlockFieldMatrixTest extends TestCase {
{ new Fraction(5), new Fraction(6) }
});
Fraction[] b = a.operate(new Fraction[] { new Fraction(1), new Fraction(1) });
- assertEquals(a.getRowDimension(), b.length);
- assertEquals( new Fraction(3), b[0]);
- assertEquals( new Fraction(7), b[1]);
- assertEquals(new Fraction(11), b[2]);
+ Assert.assertEquals(a.getRowDimension(), b.length);
+ Assert.assertEquals( new Fraction(3), b[0]);
+ Assert.assertEquals( new Fraction(7), b[1]);
+ Assert.assertEquals(new Fraction(11), b[2]);
}
/** test transpose */
+ @Test
public void testTranspose() {
FieldMatrix m = new BlockFieldMatrix(testData);
FieldMatrix mIT = new FieldLUDecompositionImpl(m).getSolver().getInverse().transpose();
@@ -434,6 +443,7 @@ public final class BlockFieldMatrixTest extends TestCase {
}
/** test preMultiply by vector */
+ @Test
public void testPremultiplyVector() {
FieldMatrix m = new BlockFieldMatrix(testData);
TestUtils.assertEquals(m.preMultiply(testVector), preMultTest);
@@ -442,12 +452,13 @@ public final class BlockFieldMatrixTest extends TestCase {
m = new BlockFieldMatrix(bigSingular);
try {
m.preMultiply(testVector);
- fail("expecting MathIllegalArgumentException");
+ Assert.fail("expecting MathIllegalArgumentException");
} catch (MathIllegalArgumentException ex) {
// ignored
}
}
+ @Test
public void testPremultiply() {
FieldMatrix m3 = new BlockFieldMatrix(d3);
FieldMatrix m4 = new BlockFieldMatrix(d4);
@@ -463,42 +474,45 @@ public final class BlockFieldMatrixTest extends TestCase {
TestUtils.assertEquals(identity.preMultiply(mInv), mInv);
try {
m.preMultiply(new BlockFieldMatrix(bigSingular));
- fail("Expecting illegalArgumentException");
+ Assert.fail("Expecting illegalArgumentException");
} catch (MathIllegalArgumentException ex) {
// ignored
}
}
+ @Test
public void testGetVectors() {
FieldMatrix m = new BlockFieldMatrix(testData);
TestUtils.assertEquals(m.getRow(0), testDataRow1);
TestUtils.assertEquals(m.getColumn(2), testDataCol3);
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 m = new BlockFieldMatrix(testData);
- assertEquals(m.getEntry(0,1),new Fraction(2));
+ Assert.assertEquals(m.getEntry(0,1),new Fraction(2));
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 = {
@@ -515,12 +529,12 @@ public final class BlockFieldMatrixTest extends TestCase {
FieldMatrix n = new BlockFieldMatrix(matrixData2);
// Now multiply m by n
FieldMatrix 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 pInverse = new FieldLUDecompositionImpl(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 = {
@@ -531,15 +545,15 @@ public final class BlockFieldMatrixTest extends TestCase {
FieldMatrix coefficients = new BlockFieldMatrix(coefficientsData);
Fraction[] constants = {new Fraction(1), new Fraction(-2), new Fraction(1)};
Fraction[] solution = new FieldLUDecompositionImpl(coefficients).getSolver().solve(constants);
- assertEquals(new Fraction(2).multiply(solution[0]).
+ Assert.assertEquals(new Fraction(2).multiply(solution[0]).
add(new Fraction(3).multiply(solution[1])).
subtract(new Fraction(2).multiply(solution[2])),
constants[0]);
- assertEquals(new Fraction(-1).multiply(solution[0]).
+ Assert.assertEquals(new Fraction(-1).multiply(solution[0]).
add(new Fraction(7).multiply(solution[1])).
add(new Fraction(6).multiply(solution[2])),
constants[1]);
- assertEquals(new Fraction(4).multiply(solution[0]).
+ Assert.assertEquals(new Fraction(4).multiply(solution[0]).
subtract(new Fraction(3).multiply(solution[1])).
subtract(new Fraction(5).multiply(solution[2])),
constants[2]);
@@ -547,6 +561,7 @@ public final class BlockFieldMatrixTest extends TestCase {
}
// test submatrix accessors
+ @Test
public void testGetSubMatrix() {
FieldMatrix m = new BlockFieldMatrix(subTestData);
checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0);
@@ -571,9 +586,9 @@ public final class BlockFieldMatrixTest extends TestCase {
try {
FieldMatrix sub = m.getSubMatrix(startRow, endRow, startColumn, endColumn);
if (reference != null) {
- assertEquals(new BlockFieldMatrix(reference), sub);
+ Assert.assertEquals(new BlockFieldMatrix(reference), sub);
} else {
- fail("Expecting OutOfRangeException or NotStrictlyPositiveException"
+ Assert.fail("Expecting OutOfRangeException or NotStrictlyPositiveException"
+ " or NumberIsTooSmallException or NoDataException");
}
} catch (OutOfRangeException e) {
@@ -600,9 +615,9 @@ public final class BlockFieldMatrixTest extends TestCase {
try {
FieldMatrix sub = m.getSubMatrix(selectedRows, selectedColumns);
if (reference != null) {
- assertEquals(new BlockFieldMatrix(reference), sub);
+ Assert.assertEquals(new BlockFieldMatrix(reference), sub);
} else {
- fail("Expecting OutOfRangeException");
+ Assert.fail("Expecting OutOfRangeException");
}
} catch (OutOfRangeException e) {
if (reference != null) {
@@ -623,6 +638,7 @@ public final class BlockFieldMatrixTest extends TestCase {
}
}
+ @Test
public void testGetSetMatrixLarge() {
int n = 3 * BlockFieldMatrix.BLOCK_SIZE;
FieldMatrix m =
@@ -634,16 +650,16 @@ public final class BlockFieldMatrixTest extends TestCase {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if ((i < 2) || (i > n - 3) || (j < 2) || (j > n - 3)) {
- assertEquals(new Fraction(0), m.getEntry(i, j));
+ Assert.assertEquals(new Fraction(0), m.getEntry(i, j));
} else {
- assertEquals(new Fraction(1), m.getEntry(i, j));
+ Assert.assertEquals(new Fraction(1), m.getEntry(i, j));
}
}
}
- assertEquals(sub, m.getSubMatrix(2, n - 3, 2, n - 3));
-
+ Assert.assertEquals(sub, m.getSubMatrix(2, n - 3, 2, n - 3));
}
+ @Test
public void testCopySubMatrix() {
FieldMatrix m = new BlockFieldMatrix(subTestData);
checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0);
@@ -672,9 +688,9 @@ public final class BlockFieldMatrixTest extends TestCase {
new Fraction[reference.length][reference[0].length];
m.copySubMatrix(startRow, endRow, startColumn, endColumn, sub);
if (reference != null) {
- assertEquals(new BlockFieldMatrix(reference), new BlockFieldMatrix(sub));
+ Assert.assertEquals(new BlockFieldMatrix(reference), new BlockFieldMatrix(sub));
} else {
- fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
+ Assert.fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
}
} catch (OutOfRangeException e) {
if (reference != null) {
@@ -699,9 +715,9 @@ public final class BlockFieldMatrixTest extends TestCase {
new Fraction[reference.length][reference[0].length];
m.copySubMatrix(selectedRows, selectedColumns, sub);
if (reference != null) {
- assertEquals(new BlockFieldMatrix(reference), new BlockFieldMatrix(sub));
+ Assert.assertEquals(new BlockFieldMatrix(reference), new BlockFieldMatrix(sub));
} else {
- fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
+ Assert.fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
}
} catch (OutOfRangeException e) {
if (reference != null) {
@@ -718,46 +734,49 @@ public final class BlockFieldMatrixTest extends TestCase {
}
}
+ @Test
public void testGetRowMatrix() {
FieldMatrix m = new BlockFieldMatrix(subTestData);
FieldMatrix mRow0 = new BlockFieldMatrix(subRow0);
FieldMatrix mRow3 = new BlockFieldMatrix(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 testSetRowMatrix() {
FieldMatrix m = new BlockFieldMatrix(subTestData);
FieldMatrix mRow3 = new BlockFieldMatrix(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 testGetSetRowMatrixLarge() {
int n = 3 * BlockFieldMatrix.BLOCK_SIZE;
FieldMatrix m =
@@ -769,56 +788,59 @@ public final class BlockFieldMatrixTest extends TestCase {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i != 2) {
- assertEquals(new Fraction(0), m.getEntry(i, j));
+ Assert.assertEquals(new Fraction(0), m.getEntry(i, j));
} else {
- assertEquals(new Fraction(1), m.getEntry(i, j));
+ Assert.assertEquals(new Fraction(1), m.getEntry(i, j));
}
}
}
- assertEquals(sub, m.getRowMatrix(2));
+ Assert.assertEquals(sub, m.getRowMatrix(2));
}
+ @Test
public void testGetColumnMatrix() {
FieldMatrix m = new BlockFieldMatrix(subTestData);
FieldMatrix mColumn1 = new BlockFieldMatrix(subColumn1);
FieldMatrix mColumn3 = new BlockFieldMatrix(subColumn3);
- assertEquals(mColumn1, m.getColumnMatrix(1));
- assertEquals(mColumn3, m.getColumnMatrix(3));
+ Assert.assertEquals(mColumn1, m.getColumnMatrix(1));
+ Assert.assertEquals(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() {
FieldMatrix m = new BlockFieldMatrix(subTestData);
FieldMatrix mColumn3 = new BlockFieldMatrix(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 testGetSetColumnMatrixLarge() {
int n = 3 * BlockFieldMatrix.BLOCK_SIZE;
FieldMatrix m =
@@ -830,56 +852,59 @@ public final class BlockFieldMatrixTest extends TestCase {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (j != 2) {
- assertEquals(new Fraction(0), m.getEntry(i, j));
+ Assert.assertEquals(new Fraction(0), m.getEntry(i, j));
} else {
- assertEquals(new Fraction(1), m.getEntry(i, j));
+ Assert.assertEquals(new Fraction(1), m.getEntry(i, j));
}
}
}
- assertEquals(sub, m.getColumnMatrix(2));
+ Assert.assertEquals(sub, m.getColumnMatrix(2));
}
+ @Test
public void testGetRowVector() {
FieldMatrix m = new BlockFieldMatrix(subTestData);
FieldVector mRow0 = new ArrayFieldVector(subRow0[0]);
FieldVector mRow3 = new ArrayFieldVector(subRow3[0]);
- assertEquals(mRow0, m.getRowVector(0));
- assertEquals(mRow3, m.getRowVector(3));
+ Assert.assertEquals(mRow0, m.getRowVector(0));
+ Assert.assertEquals(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() {
FieldMatrix m = new BlockFieldMatrix(subTestData);
FieldVector mRow3 = new ArrayFieldVector(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 ArrayFieldVector(FractionField.getInstance(), 5));
- fail("Expecting MatrixDimensionMismatchException");
+ Assert.fail("Expecting MatrixDimensionMismatchException");
} catch (MatrixDimensionMismatchException ex) {
// expected
}
}
+ @Test
public void testGetSetRowVectorLarge() {
int n = 3 * BlockFieldMatrix.BLOCK_SIZE;
FieldMatrix m = new BlockFieldMatrix(FractionField.getInstance(), n, n);
@@ -889,56 +914,59 @@ public final class BlockFieldMatrixTest extends TestCase {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i != 2) {
- assertEquals(new Fraction(0), m.getEntry(i, j));
+ Assert.assertEquals(new Fraction(0), m.getEntry(i, j));
} else {
- assertEquals(new Fraction(1), m.getEntry(i, j));
+ Assert.assertEquals(new Fraction(1), m.getEntry(i, j));
}
}
}
- assertEquals(sub, m.getRowVector(2));
+ Assert.assertEquals(sub, m.getRowVector(2));
}
+ @Test
public void testGetColumnVector() {
FieldMatrix m = new BlockFieldMatrix(subTestData);
FieldVector mColumn1 = columnToVector(subColumn1);
FieldVector mColumn3 = columnToVector(subColumn3);
- assertEquals(mColumn1, m.getColumnVector(1));
- assertEquals(mColumn3, m.getColumnVector(3));
+ Assert.assertEquals(mColumn1, m.getColumnVector(1));
+ Assert.assertEquals(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() {
FieldMatrix m = new BlockFieldMatrix(subTestData);
FieldVector 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 ArrayFieldVector(FractionField.getInstance(), 5));
- fail("Expecting MatrixDimensionMismatchException");
+ Assert.fail("Expecting MatrixDimensionMismatchException");
} catch (MatrixDimensionMismatchException ex) {
// expected
}
}
+ @Test
public void testGetSetColumnVectorLarge() {
int n = 3 * BlockFieldMatrix.BLOCK_SIZE;
FieldMatrix m = new BlockFieldMatrix(FractionField.getInstance(), n, n);
@@ -948,13 +976,13 @@ public final class BlockFieldMatrixTest extends TestCase {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (j != 2) {
- assertEquals(new Fraction(0), m.getEntry(i, j));
+ Assert.assertEquals(new Fraction(0), m.getEntry(i, j));
} else {
- assertEquals(new Fraction(1), m.getEntry(i, j));
+ Assert.assertEquals(new Fraction(1), m.getEntry(i, j));
}
}
}
- assertEquals(sub, m.getColumnVector(2));
+ Assert.assertEquals(sub, m.getColumnVector(2));
}
@@ -966,43 +994,46 @@ public final class BlockFieldMatrixTest extends TestCase {
return new ArrayFieldVector(data, false);
}
+ @Test
public void testGetRow() {
FieldMatrix m = new BlockFieldMatrix(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() {
FieldMatrix m = new BlockFieldMatrix(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 Fraction[5]);
- fail("Expecting MatrixDimensionMismatchException");
+ Assert.fail("Expecting MatrixDimensionMismatchException");
} catch (MatrixDimensionMismatchException ex) {
// expected
}
}
+ @Test
public void testGetSetRowLarge() {
int n = 3 * BlockFieldMatrix.BLOCK_SIZE;
FieldMatrix m = new BlockFieldMatrix(FractionField.getInstance(), n, n);
@@ -1013,9 +1044,9 @@ public final class BlockFieldMatrixTest extends TestCase {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i != 2) {
- assertEquals(new Fraction(0), m.getEntry(i, j));
+ Assert.assertEquals(new Fraction(0), m.getEntry(i, j));
} else {
- assertEquals(new Fraction(1), m.getEntry(i, j));
+ Assert.assertEquals(new Fraction(1), m.getEntry(i, j));
}
}
}
@@ -1023,6 +1054,7 @@ public final class BlockFieldMatrixTest extends TestCase {
}
+ @Test
public void testGetColumn() {
FieldMatrix m = new BlockFieldMatrix(subTestData);
Fraction[] mColumn1 = columnToArray(subColumn1);
@@ -1031,38 +1063,40 @@ public final class BlockFieldMatrixTest extends TestCase {
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() {
FieldMatrix m = new BlockFieldMatrix(subTestData);
Fraction[] 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 Fraction[5]);
- fail("Expecting MatrixDimensionMismatchException");
+ Assert.fail("Expecting MatrixDimensionMismatchException");
} catch (MatrixDimensionMismatchException ex) {
// expected
}
}
+ @Test
public void testGetSetColumnLarge() {
int n = 3 * BlockFieldMatrix.BLOCK_SIZE;
FieldMatrix m = new BlockFieldMatrix(FractionField.getInstance(), n, n);
@@ -1073,9 +1107,9 @@ public final class BlockFieldMatrixTest extends TestCase {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (j != 2) {
- assertEquals(new Fraction(0), m.getEntry(i, j));
+ Assert.assertEquals(new Fraction(0), m.getEntry(i, j));
} else {
- assertEquals(new Fraction(1), m.getEntry(i, j));
+ Assert.assertEquals(new Fraction(1), m.getEntry(i, j));
}
}
}
@@ -1092,46 +1126,49 @@ public final class BlockFieldMatrixTest extends TestCase {
}
private void checkArrays(Fraction[] expected, Fraction[] 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]);
}
}
+ @Test
public void testEqualsAndHashCode() {
BlockFieldMatrix m = new BlockFieldMatrix(testData);
BlockFieldMatrix m1 = (BlockFieldMatrix) m.copy();
BlockFieldMatrix mt = (BlockFieldMatrix) 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 BlockFieldMatrix(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 BlockFieldMatrix(bigSingular)));
}
+ @Test
public void testToString() {
BlockFieldMatrix m = new BlockFieldMatrix(testData);
- assertEquals("BlockFieldMatrix{{1,2,3},{2,5,3},{1,0,8}}", m.toString());
+ Assert.assertEquals("BlockFieldMatrix{{1,2,3},{2,5,3},{1,0,8}}", m.toString());
}
+ @Test
public void testSetSubMatrix() throws Exception {
BlockFieldMatrix m = new BlockFieldMatrix(testData);
m.setSubMatrix(detData2,1,1);
FieldMatrix expected = new BlockFieldMatrix
(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 = new BlockFieldMatrix
(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 = new BlockFieldMatrix
(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
BlockFieldMatrix matrix =
@@ -1150,25 +1187,25 @@ public final class BlockFieldMatrixTest extends TestCase {
{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
}
@@ -1176,7 +1213,7 @@ public final class BlockFieldMatrixTest extends TestCase {
// null
try {
m.setSubMatrix(null,1,1);
- fail("expecting NullPointerException");
+ Assert.fail("expecting NullPointerException");
} catch (NullPointerException e) {
// expected
}
@@ -1184,7 +1221,7 @@ public final class BlockFieldMatrixTest extends TestCase {
// 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
}
@@ -1192,13 +1229,13 @@ public final class BlockFieldMatrixTest extends TestCase {
// empty
try {
m.setSubMatrix(new Fraction[][] {{}}, 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;
@@ -1207,87 +1244,88 @@ public final class BlockFieldMatrixTest extends TestCase {
m.walkInRowOrder(new SetVisitor());
GetVisitor getVisitor = new GetVisitor();
m.walkInOptimizedOrder(getVisitor);
- assertEquals(rows * columns, getVisitor.getCount());
+ Assert.assertEquals(rows * columns, getVisitor.getCount());
m = new BlockFieldMatrix(FractionField.getInstance(), 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(new Fraction(0), m.getEntry(i, 0));
- assertEquals(new Fraction(0), m.getEntry(i, columns - 1));
+ Assert.assertEquals(new Fraction(0), m.getEntry(i, 0));
+ Assert.assertEquals(new Fraction(0), m.getEntry(i, columns - 1));
}
for (int j = 0; j < columns; ++j) {
- assertEquals(new Fraction(0), m.getEntry(0, j));
- assertEquals(new Fraction(0), m.getEntry(rows - 1, j));
+ Assert.assertEquals(new Fraction(0), m.getEntry(0, j));
+ Assert.assertEquals(new Fraction(0), m.getEntry(rows - 1, j));
}
m = new BlockFieldMatrix(FractionField.getInstance(), 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 BlockFieldMatrix(FractionField.getInstance(), 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(new Fraction(0), m.getEntry(i, 0));
- assertEquals(new Fraction(0), m.getEntry(i, columns - 1));
+ Assert.assertEquals(new Fraction(0), m.getEntry(i, 0));
+ Assert.assertEquals(new Fraction(0), m.getEntry(i, columns - 1));
}
for (int j = 0; j < columns; ++j) {
- assertEquals(new Fraction(0), m.getEntry(0, j));
- assertEquals(new Fraction(0), m.getEntry(rows - 1, j));
+ Assert.assertEquals(new Fraction(0), m.getEntry(0, j));
+ Assert.assertEquals(new Fraction(0), m.getEntry(rows - 1, j));
}
m = new BlockFieldMatrix(FractionField.getInstance(), 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 BlockFieldMatrix(FractionField.getInstance(), 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(new Fraction(0), m.getEntry(i, 0));
- assertEquals(new Fraction(0), m.getEntry(i, columns - 1));
+ Assert.assertEquals(new Fraction(0), m.getEntry(i, 0));
+ Assert.assertEquals(new Fraction(0), m.getEntry(i, columns - 1));
}
for (int j = 0; j < columns; ++j) {
- assertEquals(new Fraction(0), m.getEntry(0, j));
- assertEquals(new Fraction(0), m.getEntry(rows - 1, j));
+ Assert.assertEquals(new Fraction(0), m.getEntry(0, j));
+ Assert.assertEquals(new Fraction(0), m.getEntry(rows - 1, j));
}
m = new BlockFieldMatrix(FractionField.getInstance(), 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 BlockFieldMatrix(FractionField.getInstance(), 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(new Fraction(0), m.getEntry(i, 0));
- assertEquals(new Fraction(0), m.getEntry(i, columns - 1));
+ Assert.assertEquals(new Fraction(0), m.getEntry(i, 0));
+ Assert.assertEquals(new Fraction(0), m.getEntry(i, columns - 1));
}
for (int j = 0; j < columns; ++j) {
- assertEquals(new Fraction(0), m.getEntry(0, j));
- assertEquals(new Fraction(0), m.getEntry(rows - 1, j));
+ Assert.assertEquals(new Fraction(0), m.getEntry(0, j));
+ Assert.assertEquals(new Fraction(0), m.getEntry(rows - 1, j));
}
}
+ @Test
public void testSerial() {
BlockFieldMatrix m = new BlockFieldMatrix(testData);
- assertEquals(m,TestUtils.serializeAndRecover(m));
+ Assert.assertEquals(m,TestUtils.serializeAndRecover(m));
}
private static class SetVisitor extends DefaultFieldMatrixChangingVisitor {
@@ -1309,7 +1347,7 @@ public final class BlockFieldMatrixTest extends TestCase {
@Override
public void visit(int i, int j, Fraction value) {
++count;
- assertEquals(new Fraction(i * 11 + j, 11), value);
+ Assert.assertEquals(new Fraction(i * 11 + j, 11), value);
}
public int getCount() {
return count;
@@ -1331,6 +1369,5 @@ public final class BlockFieldMatrixTest extends TestCase {
}
return m;
}
-
}
diff --git a/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java b/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java
index 1c9ac1b2f..c0af0479a 100644
--- a/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java
+++ b/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java
@@ -19,16 +19,15 @@ package org.apache.commons.math.linear;
import java.util.Arrays;
import java.util.Random;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.Assert;
import org.apache.commons.math.TestUtils;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.util.FastMath;
-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;
/**
@@ -37,7 +36,7 @@ import org.apache.commons.math.exception.MathIllegalArgumentException;
* @version $Revision$ $Date$
*/
-public final class BlockRealMatrixTest extends TestCase {
+public final class BlockRealMatrixTest {
// 3 x 3 identity matrix
protected double[][] id = { {1d,0d,0d}, {0d,1d,0d}, {0d,0d,1d} };
@@ -99,34 +98,33 @@ public final class BlockRealMatrixTest extends TestCase {
protected double entryTolerance = 10E-16;
protected double normTolerance = 10E-14;
- public BlockRealMatrixTest(String name) {
- super(name);
- }
-
/** test dimensions */
+ @Test
public void testDimensions() {
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix m2 = new BlockRealMatrix(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() {
Random r = new Random(66636328996002l);
BlockRealMatrix m1 = createRandomMatrix(r, 47, 83);
BlockRealMatrix m2 = new BlockRealMatrix(m1.getData());
- assertEquals(m1, m2);
+ Assert.assertEquals(m1, m2);
BlockRealMatrix m3 = new BlockRealMatrix(testData);
BlockRealMatrix m4 = new BlockRealMatrix(m3.getData());
- assertEquals(m3, m4);
+ Assert.assertEquals(m3, m4);
}
/** test add */
+ @Test
public void testAdd() {
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix mInv = new BlockRealMatrix(testDataInv);
@@ -134,7 +132,7 @@ public final class BlockRealMatrixTest extends TestCase {
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);
}
@@ -142,48 +140,53 @@ public final class BlockRealMatrixTest extends TestCase {
}
/** test add failure */
+ @Test
public void testAddFail() {
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix m2 = new BlockRealMatrix(testData2);
try {
m.add(m2);
- fail("MathIllegalArgumentException expected");
+ Assert.fail("MathIllegalArgumentException expected");
} catch (MathIllegalArgumentException ex) {
// ignored
}
}
/** test norm */
+ @Test
public void testNorm() {
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix m2 = new BlockRealMatrix(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() {
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix m2 = new BlockRealMatrix(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 m-n = m + -n */
+ @Test
public void testPlusMinus() {
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix m2 = new BlockRealMatrix(testDataInv);
assertClose(m.subtract(m2), m2.scalarMultiply(-1d).add(m), entryTolerance);
try {
m.subtract(new BlockRealMatrix(testData2));
- fail("Expecting illegalArgumentException");
+ Assert.fail("Expecting illegalArgumentException");
} catch (MathIllegalArgumentException ex) {
// ignored
}
}
/** test multiply */
- public void testMultiply() {
+ @Test
+ public void testMultiply() {
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix mInv = new BlockRealMatrix(testDataInv);
BlockRealMatrix identity = new BlockRealMatrix(id);
@@ -195,14 +198,14 @@ public final class BlockRealMatrixTest extends TestCase {
assertClose(m2.multiply(identity), m2, entryTolerance);
try {
m.multiply(new BlockRealMatrix(bigSingular));
- fail("Expecting illegalArgumentException");
+ Assert.fail("Expecting illegalArgumentException");
} catch (MathIllegalArgumentException ex) {
// expected
}
}
+ @Test
public void testSeveralBlocks() {
-
RealMatrix m = new BlockRealMatrix(35, 71);
for (int i = 0; i < m.getRowDimension(); ++i) {
for (int j = 0; j < m.getColumnDimension(); ++j) {
@@ -211,25 +214,25 @@ public final class BlockRealMatrixTest extends TestCase {
}
RealMatrix mT = m.transpose();
- assertEquals(m.getRowDimension(), mT.getColumnDimension());
- assertEquals(m.getColumnDimension(), mT.getRowDimension());
+ Assert.assertEquals(m.getRowDimension(), mT.getColumnDimension());
+ Assert.assertEquals(m.getColumnDimension(), mT.getRowDimension());
for (int i = 0; i < mT.getRowDimension(); ++i) {
for (int j = 0; j < mT.getColumnDimension(); ++j) {
- assertEquals(m.getEntry(j, i), mT.getEntry(i, j), 0);
+ Assert.assertEquals(m.getEntry(j, i), mT.getEntry(i, j), 0);
}
}
RealMatrix mPm = m.add(m);
for (int i = 0; i < mPm.getRowDimension(); ++i) {
for (int j = 0; j < mPm.getColumnDimension(); ++j) {
- assertEquals(2 * m.getEntry(i, j), mPm.getEntry(i, j), 0);
+ Assert.assertEquals(2 * m.getEntry(i, j), mPm.getEntry(i, j), 0);
}
}
RealMatrix mPmMm = mPm.subtract(m);
for (int i = 0; i < mPmMm.getRowDimension(); ++i) {
for (int j = 0; j < mPmMm.getColumnDimension(); ++j) {
- assertEquals(m.getEntry(i, j), mPmMm.getEntry(i, j), 0);
+ Assert.assertEquals(m.getEntry(i, j), mPmMm.getEntry(i, j), 0);
}
}
@@ -240,7 +243,7 @@ public final class BlockRealMatrixTest extends TestCase {
for (int k = 0; k < mT.getColumnDimension(); ++k) {
sum += (k + i / 1024.0) * (k + j / 1024.0);
}
- assertEquals(sum, mTm.getEntry(i, j), 0);
+ Assert.assertEquals(sum, mTm.getEntry(i, j), 0);
}
}
@@ -251,35 +254,35 @@ public final class BlockRealMatrixTest extends TestCase {
for (int k = 0; k < m.getColumnDimension(); ++k) {
sum += (i + k / 1024.0) * (j + k / 1024.0);
}
- assertEquals(sum, mmT.getEntry(i, j), 0);
+ Assert.assertEquals(sum, mmT.getEntry(i, j), 0);
}
}
RealMatrix sub1 = m.getSubMatrix(2, 9, 5, 20);
for (int i = 0; i < sub1.getRowDimension(); ++i) {
for (int j = 0; j < sub1.getColumnDimension(); ++j) {
- assertEquals((i + 2) + (j + 5) / 1024.0, sub1.getEntry(i, j), 0);
+ Assert.assertEquals((i + 2) + (j + 5) / 1024.0, sub1.getEntry(i, j), 0);
}
}
RealMatrix sub2 = m.getSubMatrix(10, 12, 3, 70);
for (int i = 0; i < sub2.getRowDimension(); ++i) {
for (int j = 0; j < sub2.getColumnDimension(); ++j) {
- assertEquals((i + 10) + (j + 3) / 1024.0, sub2.getEntry(i, j), 0);
+ Assert.assertEquals((i + 10) + (j + 3) / 1024.0, sub2.getEntry(i, j), 0);
}
}
RealMatrix sub3 = m.getSubMatrix(30, 34, 0, 5);
for (int i = 0; i < sub3.getRowDimension(); ++i) {
for (int j = 0; j < sub3.getColumnDimension(); ++j) {
- assertEquals((i + 30) + (j + 0) / 1024.0, sub3.getEntry(i, j), 0);
+ Assert.assertEquals((i + 30) + (j + 0) / 1024.0, sub3.getEntry(i, j), 0);
}
}
RealMatrix sub4 = m.getSubMatrix(30, 32, 62, 65);
for (int i = 0; i < sub4.getRowDimension(); ++i) {
for (int j = 0; j < sub4.getColumnDimension(); ++j) {
- assertEquals((i + 30) + (j + 62) / 1024.0, sub4.getEntry(i, j), 0);
+ Assert.assertEquals((i + 30) + (j + 62) / 1024.0, sub4.getEntry(i, j), 0);
}
}
@@ -291,33 +294,37 @@ public final class BlockRealMatrixTest extends TestCase {
private double[][] d4 = new double[][] {{1},{2},{3},{4}};
private double[][] d5 = new double[][] {{30},{70}};
+ @Test
public void testMultiply2() {
- RealMatrix m3 = new BlockRealMatrix(d3);
- RealMatrix m4 = new BlockRealMatrix(d4);
- RealMatrix m5 = new BlockRealMatrix(d5);
- assertClose(m3.multiply(m4), m5, entryTolerance);
- }
+ RealMatrix m3 = new BlockRealMatrix(d3);
+ RealMatrix m4 = new BlockRealMatrix(d4);
+ RealMatrix m5 = new BlockRealMatrix(d5);
+ assertClose(m3.multiply(m4), m5, entryTolerance);
+ }
/** test trace */
+ @Test
public void testTrace() {
RealMatrix m = new BlockRealMatrix(id);
- assertEquals("identity trace",3d,m.getTrace(),entryTolerance);
+ Assert.assertEquals("identity trace",3d,m.getTrace(),entryTolerance);
m = new BlockRealMatrix(testData2);
try {
m.getTrace();
- fail("Expecting NonSquareMatrixException");
+ Assert.fail("Expecting NonSquareMatrixException");
} catch (NonSquareMatrixException ex) {
// ignored
}
}
/** test scalarAdd */
+ @Test
public void testScalarAdd() {
RealMatrix m = new BlockRealMatrix(testData);
assertClose(new BlockRealMatrix(testDataPlus2), m.scalarAdd(2d), entryTolerance);
}
/** test operate */
+ @Test
public void testOperate() {
RealMatrix m = new BlockRealMatrix(id);
assertClose(testVector, m.operate(testVector), entryTolerance);
@@ -325,12 +332,13 @@ public final class BlockRealMatrixTest extends TestCase {
m = new BlockRealMatrix(bigSingular);
try {
m.operate(testVector);
- fail("Expecting illegalArgumentException");
+ Assert.fail("Expecting illegalArgumentException");
} catch (MathIllegalArgumentException ex) {
// ignored
}
}
+ @Test
public void testOperateLarge() {
int p = (7 * BlockRealMatrix.BLOCK_SIZE) / 2;
int q = (5 * BlockRealMatrix.BLOCK_SIZE) / 2;
@@ -344,6 +352,7 @@ public final class BlockRealMatrixTest extends TestCase {
}
}
+ @Test
public void testOperatePremultiplyLarge() {
int p = (7 * BlockRealMatrix.BLOCK_SIZE) / 2;
int q = (5 * BlockRealMatrix.BLOCK_SIZE) / 2;
@@ -358,18 +367,20 @@ public final class BlockRealMatrixTest extends TestCase {
}
/** test issue MATH-209 */
+ @Test
public void testMath209() {
RealMatrix a = new BlockRealMatrix(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 = new BlockRealMatrix(testData);
RealMatrix mIT = new LUDecompositionImpl(m).getSolver().getInverse().transpose();
@@ -381,6 +392,7 @@ public final class BlockRealMatrixTest extends TestCase {
}
/** test preMultiply by vector */
+ @Test
public void testPremultiplyVector() {
RealMatrix m = new BlockRealMatrix(testData);
assertClose(m.preMultiply(testVector), preMultTest, normTolerance);
@@ -389,12 +401,13 @@ public final class BlockRealMatrixTest extends TestCase {
m = new BlockRealMatrix(bigSingular);
try {
m.preMultiply(testVector);
- fail("expecting MathIllegalArgumentException");
+ Assert.fail("expecting MathIllegalArgumentException");
} catch (MathIllegalArgumentException ex) {
// ignored
}
}
+ @Test
public void testPremultiply() {
RealMatrix m3 = new BlockRealMatrix(d3);
RealMatrix m4 = new BlockRealMatrix(d4);
@@ -410,42 +423,45 @@ public final class BlockRealMatrixTest extends TestCase {
assertClose(identity.preMultiply(mInv), mInv, entryTolerance);
try {
m.preMultiply(new BlockRealMatrix(bigSingular));
- fail("Expecting illegalArgumentException");
+ Assert.fail("Expecting illegalArgumentException");
} catch (MathIllegalArgumentException ex) {
// ignored
}
}
+ @Test
public void testGetVectors() {
RealMatrix m = new BlockRealMatrix(testData);
assertClose(m.getRow(0), testDataRow1, entryTolerance);
assertClose(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 BlockRealMatrix(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}};
@@ -455,25 +471,26 @@ public final class BlockRealMatrixTest extends TestCase {
RealMatrix n = new BlockRealMatrix(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 BlockRealMatrix(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 BlockRealMatrix(subTestData);
checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0);
@@ -498,9 +515,9 @@ public final class BlockRealMatrixTest extends TestCase {
try {
RealMatrix sub = m.getSubMatrix(startRow, endRow, startColumn, endColumn);
if (reference != null) {
- assertEquals(new BlockRealMatrix(reference), sub);
+ Assert.assertEquals(new BlockRealMatrix(reference), sub);
} else {
- fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
+ Assert.fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
}
} catch (OutOfRangeException e) {
if (reference != null) {
@@ -522,9 +539,9 @@ public final class BlockRealMatrixTest extends TestCase {
try {
RealMatrix sub = m.getSubMatrix(selectedRows, selectedColumns);
if (reference != null) {
- assertEquals(new BlockRealMatrix(reference), sub);
+ Assert.assertEquals(new BlockRealMatrix(reference), sub);
} else {
- fail("Expecting OutOfRangeException or NumberIsTooSmallExceptiono r NoDataException");
+ Assert.fail("Expecting OutOfRangeException or NumberIsTooSmallExceptiono r NoDataException");
}
} catch (OutOfRangeException e) {
if (reference != null) {
@@ -541,6 +558,7 @@ public final class BlockRealMatrixTest extends TestCase {
}
}
+ @Test
public void testGetSetMatrixLarge() {
int n = 3 * BlockRealMatrix.BLOCK_SIZE;
RealMatrix m = new BlockRealMatrix(n, n);
@@ -550,16 +568,17 @@ public final class BlockRealMatrixTest extends TestCase {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if ((i < 2) || (i > n - 3) || (j < 2) || (j > n - 3)) {
- assertEquals(0.0, m.getEntry(i, j), 0.0);
+ Assert.assertEquals(0.0, m.getEntry(i, j), 0.0);
} else {
- assertEquals(1.0, m.getEntry(i, j), 0.0);
+ Assert.assertEquals(1.0, m.getEntry(i, j), 0.0);
}
}
}
- assertEquals(sub, m.getSubMatrix(2, n - 3, 2, n - 3));
+ Assert.assertEquals(sub, m.getSubMatrix(2, n - 3, 2, n - 3));
}
+ @Test
public void testCopySubMatrix() {
RealMatrix m = new BlockRealMatrix(subTestData);
checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0);
@@ -588,9 +607,9 @@ public final class BlockRealMatrixTest extends TestCase {
new double[reference.length][reference[0].length];
m.copySubMatrix(startRow, endRow, startColumn, endColumn, sub);
if (reference != null) {
- assertEquals(new BlockRealMatrix(reference), new BlockRealMatrix(sub));
+ Assert.assertEquals(new BlockRealMatrix(reference), new BlockRealMatrix(sub));
} else {
- fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
+ Assert.fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
}
} catch (OutOfRangeException e) {
if (reference != null) {
@@ -615,9 +634,9 @@ public final class BlockRealMatrixTest extends TestCase {
new double[reference.length][reference[0].length];
m.copySubMatrix(selectedRows, selectedColumns, sub);
if (reference != null) {
- assertEquals(new BlockRealMatrix(reference), new BlockRealMatrix(sub));
+ Assert.assertEquals(new BlockRealMatrix(reference), new BlockRealMatrix(sub));
} else {
- fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
+ Assert.fail("Expecting OutOfRangeException or NumberIsTooSmallException or NoDataException");
}
} catch (OutOfRangeException e) {
if (reference != null) {
@@ -634,46 +653,49 @@ public final class BlockRealMatrixTest extends TestCase {
}
}
+ @Test
public void testGetRowMatrix() {
RealMatrix m = new BlockRealMatrix(subTestData);
RealMatrix mRow0 = new BlockRealMatrix(subRow0);
RealMatrix mRow3 = new BlockRealMatrix(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 testSetRowMatrix() {
RealMatrix m = new BlockRealMatrix(subTestData);
RealMatrix mRow3 = new BlockRealMatrix(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 testGetSetRowMatrixLarge() {
int n = 3 * BlockRealMatrix.BLOCK_SIZE;
RealMatrix m = new BlockRealMatrix(n, n);
@@ -683,56 +705,58 @@ public final class BlockRealMatrixTest extends TestCase {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i != 2) {
- assertEquals(0.0, m.getEntry(i, j), 0.0);
+ Assert.assertEquals(0.0, m.getEntry(i, j), 0.0);
} else {
- assertEquals(1.0, m.getEntry(i, j), 0.0);
+ Assert.assertEquals(1.0, m.getEntry(i, j), 0.0);
}
}
}
- assertEquals(sub, m.getRowMatrix(2));
-
+ Assert.assertEquals(sub, m.getRowMatrix(2));
}
+ @Test
public void testGetColumnMatrix() {
RealMatrix m = new BlockRealMatrix(subTestData);
RealMatrix mColumn1 = new BlockRealMatrix(subColumn1);
RealMatrix mColumn3 = new BlockRealMatrix(subColumn3);
- assertEquals(mColumn1, m.getColumnMatrix(1));
- assertEquals(mColumn3, m.getColumnMatrix(3));
+ Assert.assertEquals(mColumn1, m.getColumnMatrix(1));
+ Assert.assertEquals(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 BlockRealMatrix(subTestData);
RealMatrix mColumn3 = new BlockRealMatrix(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 testGetSetColumnMatrixLarge() {
int n = 3 * BlockRealMatrix.BLOCK_SIZE;
RealMatrix m = new BlockRealMatrix(n, n);
@@ -742,56 +766,59 @@ public final class BlockRealMatrixTest extends TestCase {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (j != 2) {
- assertEquals(0.0, m.getEntry(i, j), 0.0);
+ Assert.assertEquals(0.0, m.getEntry(i, j), 0.0);
} else {
- assertEquals(1.0, m.getEntry(i, j), 0.0);
+ Assert.assertEquals(1.0, m.getEntry(i, j), 0.0);
}
}
}
- assertEquals(sub, m.getColumnMatrix(2));
+ Assert.assertEquals(sub, m.getColumnMatrix(2));
}
+ @Test
public void testGetRowVector() {
RealMatrix m = new BlockRealMatrix(subTestData);
RealVector mRow0 = new ArrayRealVector(subRow0[0]);
RealVector mRow3 = new ArrayRealVector(subRow3[0]);
- assertEquals(mRow0, m.getRowVector(0));
- assertEquals(mRow3, m.getRowVector(3));
+ Assert.assertEquals(mRow0, m.getRowVector(0));
+ Assert.assertEquals(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 BlockRealMatrix(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 testGetSetRowVectorLarge() {
int n = 3 * BlockRealMatrix.BLOCK_SIZE;
RealMatrix m = new BlockRealMatrix(n, n);
@@ -801,56 +828,58 @@ public final class BlockRealMatrixTest extends TestCase {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i != 2) {
- assertEquals(0.0, m.getEntry(i, j), 0.0);
+ Assert.assertEquals(0.0, m.getEntry(i, j), 0.0);
} else {
- assertEquals(1.0, m.getEntry(i, j), 0.0);
+ Assert.assertEquals(1.0, m.getEntry(i, j), 0.0);
}
}
}
- assertEquals(sub, m.getRowVector(2));
-
+ Assert.assertEquals(sub, m.getRowVector(2));
}
+ @Test
public void testGetColumnVector() {
RealMatrix m = new BlockRealMatrix(subTestData);
RealVector mColumn1 = columnToVector(subColumn1);
RealVector mColumn3 = columnToVector(subColumn3);
- assertEquals(mColumn1, m.getColumnVector(1));
- assertEquals(mColumn3, m.getColumnVector(3));
+ Assert.assertEquals(mColumn1, m.getColumnVector(1));
+ Assert.assertEquals(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 BlockRealMatrix(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
}
}
+ @Test
public void testGetSetColumnVectorLarge() {
int n = 3 * BlockRealMatrix.BLOCK_SIZE;
RealMatrix m = new BlockRealMatrix(n, n);
@@ -860,14 +889,13 @@ public final class BlockRealMatrixTest extends TestCase {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (j != 2) {
- assertEquals(0.0, m.getEntry(i, j), 0.0);
+ Assert.assertEquals(0.0, m.getEntry(i, j), 0.0);
} else {
- assertEquals(1.0, m.getEntry(i, j), 0.0);
+ Assert.assertEquals(1.0, m.getEntry(i, j), 0.0);
}
}
}
- assertEquals(sub, m.getColumnVector(2));
-
+ Assert.assertEquals(sub, m.getColumnVector(2));
}
private RealVector columnToVector(double[][] column) {
@@ -878,43 +906,46 @@ public final class BlockRealMatrixTest extends TestCase {
return new ArrayRealVector(data, false);
}
+ @Test
public void testGetRow() {
RealMatrix m = new BlockRealMatrix(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 BlockRealMatrix(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 testGetSetRowLarge() {
int n = 3 * BlockRealMatrix.BLOCK_SIZE;
RealMatrix m = new BlockRealMatrix(n, n);
@@ -925,16 +956,16 @@ public final class BlockRealMatrixTest extends TestCase {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i != 2) {
- assertEquals(0.0, m.getEntry(i, j), 0.0);
+ Assert.assertEquals(0.0, m.getEntry(i, j), 0.0);
} else {
- assertEquals(1.0, m.getEntry(i, j), 0.0);
+ Assert.assertEquals(1.0, m.getEntry(i, j), 0.0);
}
}
}
checkArrays(sub, m.getRow(2));
-
}
+ @Test
public void testGetColumn() {
RealMatrix m = new BlockRealMatrix(subTestData);
double[] mColumn1 = columnToArray(subColumn1);
@@ -943,38 +974,40 @@ public final class BlockRealMatrixTest extends TestCase {
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 BlockRealMatrix(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
}
}
+ @Test
public void testGetSetColumnLarge() {
int n = 3 * BlockRealMatrix.BLOCK_SIZE;
RealMatrix m = new BlockRealMatrix(n, n);
@@ -985,14 +1018,13 @@ public final class BlockRealMatrixTest extends TestCase {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (j != 2) {
- assertEquals(0.0, m.getEntry(i, j), 0.0);
+ Assert.assertEquals(0.0, m.getEntry(i, j), 0.0);
} else {
- assertEquals(1.0, m.getEntry(i, j), 0.0);
+ Assert.assertEquals(1.0, m.getEntry(i, j), 0.0);
}
}
}
checkArrays(sub, m.getColumn(2));
-
}
private double[] columnToArray(double[][] column) {
@@ -1004,47 +1036,50 @@ public final class BlockRealMatrixTest extends TestCase {
}
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() {
BlockRealMatrix m = new BlockRealMatrix(testData);
BlockRealMatrix m1 = m.copy();
BlockRealMatrix mt = 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 BlockRealMatrix(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 BlockRealMatrix(bigSingular)));
}
+ @Test
public void testToString() {
BlockRealMatrix m = new BlockRealMatrix(testData);
- assertEquals("BlockRealMatrix{{1.0,2.0,3.0},{2.0,5.0,3.0},{1.0,0.0,8.0}}",
+ Assert.assertEquals("BlockRealMatrix{{1.0,2.0,3.0},{2.0,5.0,3.0},{1.0,0.0,8.0}}",
m.toString());
}
+ @Test
public void testSetSubMatrix() throws Exception {
BlockRealMatrix m = new BlockRealMatrix(testData);
m.setSubMatrix(detData2,1,1);
RealMatrix expected = new BlockRealMatrix
(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 = new BlockRealMatrix
(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 = new BlockRealMatrix
(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
BlockRealMatrix matrix = new BlockRealMatrix
@@ -1052,25 +1087,25 @@ public final class BlockRealMatrixTest extends TestCase {
matrix.setSubMatrix(new double[][] {{3, 4}, {5, 6}}, 1, 1);
expected = new BlockRealMatrix
(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
}
@@ -1078,7 +1113,7 @@ public final class BlockRealMatrixTest extends TestCase {
// null
try {
m.setSubMatrix(null,1,1);
- fail("expecting NullPointerException");
+ Assert.fail("expecting NullPointerException");
} catch (NullPointerException e) {
// expected
}
@@ -1086,7 +1121,7 @@ public final class BlockRealMatrixTest extends TestCase {
// ragged
try {
m.setSubMatrix(new double[][] {{1}, {2, 3}}, 0, 0);
- fail("expecting MathIllegalArgumentException");
+ Assert.fail("expecting MathIllegalArgumentException");
} catch (MathIllegalArgumentException e) {
// expected
}
@@ -1094,13 +1129,13 @@ public final class BlockRealMatrixTest extends TestCase {
// 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;
@@ -1109,87 +1144,88 @@ public final class BlockRealMatrixTest extends TestCase {
m.walkInRowOrder(new SetVisitor());
GetVisitor getVisitor = new GetVisitor();
m.walkInOptimizedOrder(getVisitor);
- assertEquals(rows * columns, getVisitor.getCount());
+ Assert.assertEquals(rows * columns, getVisitor.getCount());
m = new BlockRealMatrix(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 BlockRealMatrix(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 BlockRealMatrix(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 BlockRealMatrix(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 BlockRealMatrix(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 BlockRealMatrix(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 BlockRealMatrix(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() {
BlockRealMatrix m = new BlockRealMatrix(testData);
- assertEquals(m,TestUtils.serializeAndRecover(m));
+ Assert.assertEquals(m,TestUtils.serializeAndRecover(m));
}
private static class SetVisitor extends DefaultRealMatrixChangingVisitor {
@@ -1204,7 +1240,7 @@ public final class BlockRealMatrixTest extends TestCase {
@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;
@@ -1215,16 +1251,16 @@ public final class BlockRealMatrixTest extends TestCase {
/** verifies that two matrices are close (1-norm) */
protected void assertClose(RealMatrix m, RealMatrix n, double tolerance) {
- assertTrue(m.subtract(n).getNorm() < tolerance);
+ Assert.assertTrue(m.subtract(n).getNorm() < tolerance);
}
/** verifies that two vectors are close (sup norm) */
protected void assertClose(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(m[i], n[i], tolerance);
+ Assert.assertEquals(m[i], n[i], tolerance);
}
}
@@ -1237,6 +1273,5 @@ public final class BlockRealMatrixTest extends TestCase {
}
return m;
}
-
}
diff --git a/src/test/java/org/apache/commons/math/linear/CholeskyDecompositionImplTest.java b/src/test/java/org/apache/commons/math/linear/CholeskyDecompositionImplTest.java
index c3448e19b..bd19da0f9 100644
--- a/src/test/java/org/apache/commons/math/linear/CholeskyDecompositionImplTest.java
+++ b/src/test/java/org/apache/commons/math/linear/CholeskyDecompositionImplTest.java
@@ -17,13 +17,8 @@
package org.apache.commons.math.linear;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.commons.math.exception.NonSquareMatrixException;
-import org.apache.commons.math.exception.NonPositiveDefiniteMatrixException;
-import org.apache.commons.math.exception.NonSymmetricMatrixException;
import org.junit.Test;
+import org.junit.Assert;
public class CholeskyDecompositionImplTest {
@@ -40,10 +35,10 @@ public class CholeskyDecompositionImplTest {
public void testDimensions() {
CholeskyDecomposition llt =
new CholeskyDecompositionImpl(MatrixUtils.createRealMatrix(testData));
- assertEquals(testData.length, llt.getL().getRowDimension());
- assertEquals(testData.length, llt.getL().getColumnDimension());
- assertEquals(testData.length, llt.getLT().getRowDimension());
- assertEquals(testData.length, llt.getLT().getColumnDimension());
+ Assert.assertEquals(testData.length, llt.getL().getRowDimension());
+ Assert.assertEquals(testData.length, llt.getL().getColumnDimension());
+ Assert.assertEquals(testData.length, llt.getLT().getRowDimension());
+ Assert.assertEquals(testData.length, llt.getLT().getColumnDimension());
}
/** test non-square matrix */
@@ -91,7 +86,7 @@ public class CholeskyDecompositionImplTest {
RealMatrix l = llt.getL();
RealMatrix lt = llt.getLT();
double norm = l.multiply(lt).subtract(matrix).getNorm();
- assertEquals(0, norm, 1.0e-15);
+ Assert.assertEquals(0, norm, 1.0e-15);
}
/** test that L is lower triangular */
@@ -101,7 +96,7 @@ public class CholeskyDecompositionImplTest {
RealMatrix l = new CholeskyDecompositionImpl(matrix).getL();
for (int i = 0; i < l.getRowDimension(); i++) {
for (int j = i + 1; j < l.getColumnDimension(); j++) {
- assertEquals(0.0, l.getEntry(i, j), 0.0);
+ Assert.assertEquals(0.0, l.getEntry(i, j), 0.0);
}
}
}
@@ -114,7 +109,7 @@ public class CholeskyDecompositionImplTest {
RealMatrix l = llt.getL();
RealMatrix lt = llt.getLT();
double norm = l.subtract(lt.transpose()).getNorm();
- assertEquals(0, norm, 1.0e-15);
+ Assert.assertEquals(0, norm, 1.0e-15);
}
/** test matrices values */
@@ -132,14 +127,12 @@ public class CholeskyDecompositionImplTest {
// check values against known references
RealMatrix l = llt.getL();
- assertEquals(0, l.subtract(lRef).getNorm(), 1.0e-13);
+ Assert.assertEquals(0, l.subtract(lRef).getNorm(), 1.0e-13);
RealMatrix lt = llt.getLT();
- assertEquals(0, lt.subtract(lRef.transpose()).getNorm(), 1.0e-13);
+ Assert.assertEquals(0, lt.subtract(lRef.transpose()).getNorm(), 1.0e-13);
// check the same cached instance is returned the second time
- assertTrue(l == llt.getL());
- assertTrue(lt == llt.getLT());
-
+ Assert.assertTrue(l == llt.getL());
+ Assert.assertTrue(lt == llt.getLT());
}
-
}
diff --git a/src/test/java/org/apache/commons/math/linear/EigenSolverTest.java b/src/test/java/org/apache/commons/math/linear/EigenSolverTest.java
index ec456fc0f..70a279603 100644
--- a/src/test/java/org/apache/commons/math/linear/EigenSolverTest.java
+++ b/src/test/java/org/apache/commons/math/linear/EigenSolverTest.java
@@ -20,73 +20,75 @@ package org.apache.commons.math.linear;
import java.util.Random;
import org.apache.commons.math.util.MathUtils;
-import org.apache.commons.math.exception.SingularMatrixException;
import org.apache.commons.math.exception.MathIllegalArgumentException;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.Assert;
-public class EigenSolverTest extends TestCase {
-
- private double[] refValues;
- private RealMatrix matrix;
-
- public EigenSolverTest(String name) {
- super(name);
- }
+public class EigenSolverTest {
/** test non invertible matrix */
+ @Test
public void testNonInvertible() {
Random r = new Random(9994100315209l);
RealMatrix m =
EigenDecompositionImplTest.createTestMatrix(r, new double[] { 1.0, 0.0, -1.0, -2.0, -3.0 });
DecompositionSolver es = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN).getSolver();
- assertFalse(es.isNonSingular());
+ Assert.assertFalse(es.isNonSingular());
try {
es.getInverse();
- fail("an exception should have been thrown");
+ Assert.fail("an exception should have been thrown");
} catch (SingularMatrixException ime) {
// expected behavior
}
}
/** test invertible matrix */
+ @Test
public void testInvertible() {
Random r = new Random(9994100315209l);
RealMatrix m =
EigenDecompositionImplTest.createTestMatrix(r, new double[] { 1.0, 0.5, -1.0, -2.0, -3.0 });
DecompositionSolver es = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN).getSolver();
- assertTrue(es.isNonSingular());
+ Assert.assertTrue(es.isNonSingular());
RealMatrix inverse = es.getInverse();
RealMatrix error =
m.multiply(inverse).subtract(MatrixUtils.createRealIdentityMatrix(m.getRowDimension()));
- assertEquals(0, error.getNorm(), 4.0e-15);
+ Assert.assertEquals(0, error.getNorm(), 4.0e-15);
}
/** test solve dimension errors */
+ @Test
public void testSolveDimensionErrors() {
+ final double[] refValues = new double[] {
+ 2.003, 2.002, 2.001, 1.001, 1.000, 0.001
+ };
+ final RealMatrix matrix = EigenDecompositionImplTest.createTestMatrix(new Random(35992629946426l), refValues);
+
DecompositionSolver es = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN).getSolver();
RealMatrix b = MatrixUtils.createRealMatrix(new double[2][2]);
try {
es.solve(b);
- fail("an exception should have been thrown");
+ Assert.fail("an exception should have been thrown");
} catch (MathIllegalArgumentException iae) {
// expected behavior
}
try {
es.solve(b.getColumn(0));
- fail("an exception should have been thrown");
+ Assert.fail("an exception should have been thrown");
} catch (MathIllegalArgumentException iae) {
// expected behavior
}
try {
es.solve(new ArrayRealVectorTest.RealVectorTestImpl(b.getColumn(0)));
- fail("an exception should have been thrown");
+ Assert.fail("an exception should have been thrown");
} catch (MathIllegalArgumentException iae) {
// expected behavior
}
}
/** test solve */
+ @Test
public void testSolve() {
RealMatrix m = MatrixUtils.createRealMatrix(new double[][] {
{ 91, 5, 29, 32, 40, 14 },
@@ -116,18 +118,18 @@ public class EigenSolverTest extends TestCase {
// using RealMatrix
RealMatrix solution=es.solve(b);
- assertEquals(0, solution.subtract(xRef).getNorm(), 2.5e-12);
+ Assert.assertEquals(0, solution.subtract(xRef).getNorm(), 2.5e-12);
// using double[]
for (int i = 0; i < b.getColumnDimension(); ++i) {
- assertEquals(0,
+ Assert.assertEquals(0,
new ArrayRealVector(es.solve(b.getColumn(i))).subtract(xRef.getColumnVector(i)).getNorm(),
2.0e-11);
}
// using Array2DRowRealMatrix
for (int i = 0; i < b.getColumnDimension(); ++i) {
- assertEquals(0,
+ Assert.assertEquals(0,
es.solve(b.getColumnVector(i)).subtract(xRef.getColumnVector(i)).getNorm(),
2.0e-11);
}
@@ -136,25 +138,9 @@ public class EigenSolverTest extends TestCase {
for (int i = 0; i < b.getColumnDimension(); ++i) {
ArrayRealVectorTest.RealVectorTestImpl v =
new ArrayRealVectorTest.RealVectorTestImpl(b.getColumn(i));
- assertEquals(0,
+ Assert.assertEquals(0,
es.solve(v).subtract(xRef.getColumnVector(i)).getNorm(),
2.0e-11);
}
-
}
-
- @Override
- public void setUp() {
- refValues = new double[] {
- 2.003, 2.002, 2.001, 1.001, 1.000, 0.001
- };
- matrix = EigenDecompositionImplTest.createTestMatrix(new Random(35992629946426l), refValues);
- }
-
- @Override
- public void tearDown() {
- refValues = null;
- matrix = null;
- }
-
}
diff --git a/src/test/java/org/apache/commons/math/linear/FieldLUDecompositionImplTest.java b/src/test/java/org/apache/commons/math/linear/FieldLUDecompositionImplTest.java
index c1a2a2536..6cf90a819 100644
--- a/src/test/java/org/apache/commons/math/linear/FieldLUDecompositionImplTest.java
+++ b/src/test/java/org/apache/commons/math/linear/FieldLUDecompositionImplTest.java
@@ -17,14 +17,14 @@
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.fraction.Fraction;
import org.apache.commons.math.fraction.FractionField;
-import org.apache.commons.math.exception.NonSquareMatrixException;
-public class FieldLUDecompositionImplTest extends TestCase {
+public class FieldLUDecompositionImplTest {
private Fraction[][] testData = {
{ new Fraction(1), new Fraction(2), new Fraction(3)},
{ new Fraction(2), new Fraction(5), new Fraction(3)},
@@ -53,24 +53,22 @@ public class FieldLUDecompositionImplTest extends TestCase {
{ new Fraction(3), new Fraction(7), new Fraction(6), new Fraction(8) }
}; // 4th row = 1st + 2nd
- public FieldLUDecompositionImplTest(String name) {
- super(name);
- }
-
/** test dimensions */
+ @Test
public void testDimensions() {
FieldMatrix matrix = new Array2DRowFieldMatrix(testData);
FieldLUDecomposition LU = new FieldLUDecompositionImpl(matrix);
- assertEquals(testData.length, LU.getL().getRowDimension());
- assertEquals(testData.length, LU.getL().getColumnDimension());
- assertEquals(testData.length, LU.getU().getRowDimension());
- assertEquals(testData.length, LU.getU().getColumnDimension());
- assertEquals(testData.length, LU.getP().getRowDimension());
- assertEquals(testData.length, LU.getP().getColumnDimension());
+ Assert.assertEquals(testData.length, LU.getL().getRowDimension());
+ Assert.assertEquals(testData.length, LU.getL().getColumnDimension());
+ Assert.assertEquals(testData.length, LU.getU().getRowDimension());
+ Assert.assertEquals(testData.length, LU.getU().getColumnDimension());
+ Assert.assertEquals(testData.length, LU.getP().getRowDimension());
+ Assert.assertEquals(testData.length, LU.getP().getColumnDimension());
}
/** test non-square matrix */
+ @Test
public void testNonSquare() {
try {
new FieldLUDecompositionImpl(new Array2DRowFieldMatrix(new Fraction[][] {
@@ -78,13 +76,14 @@ public class FieldLUDecompositionImplTest extends TestCase {
{ Fraction.ZERO, Fraction.ZERO },
{ Fraction.ZERO, Fraction.ZERO }
}));
- fail("Expected NonSquareMatrixException");
+ Assert.fail("Expected NonSquareMatrixException");
} catch (NonSquareMatrixException ime) {
// expected behavior
}
}
/** test PA = LU */
+ @Test
public void testPAEqualLU() {
FieldMatrix matrix = new Array2DRowFieldMatrix(testData);
FieldLUDecomposition lu = new FieldLUDecompositionImpl(matrix);
@@ -112,44 +111,47 @@ public class FieldLUDecompositionImplTest extends TestCase {
matrix = new Array2DRowFieldMatrix(singular);
lu = new FieldLUDecompositionImpl(matrix);
- assertFalse(lu.getSolver().isNonSingular());
- assertNull(lu.getL());
- assertNull(lu.getU());
- assertNull(lu.getP());
+ Assert.assertFalse(lu.getSolver().isNonSingular());
+ Assert.assertNull(lu.getL());
+ Assert.assertNull(lu.getU());
+ Assert.assertNull(lu.getP());
matrix = new Array2DRowFieldMatrix(bigSingular);
lu = new FieldLUDecompositionImpl(matrix);
- assertFalse(lu.getSolver().isNonSingular());
- assertNull(lu.getL());
- assertNull(lu.getU());
- assertNull(lu.getP());
+ Assert.assertFalse(lu.getSolver().isNonSingular());
+ Assert.assertNull(lu.getL());
+ Assert.assertNull(lu.getU());
+ Assert.assertNull(lu.getP());
}
/** test that L is lower triangular with unit diagonal */
+ @Test
public void testLLowerTriangular() {
FieldMatrix matrix = new Array2DRowFieldMatrix(testData);
FieldMatrix l = new FieldLUDecompositionImpl(matrix).getL();
for (int i = 0; i < l.getRowDimension(); i++) {
- assertEquals(Fraction.ONE, l.getEntry(i, i));
+ Assert.assertEquals(Fraction.ONE, l.getEntry(i, i));
for (int j = i + 1; j < l.getColumnDimension(); j++) {
- assertEquals(Fraction.ZERO, l.getEntry(i, j));
+ Assert.assertEquals(Fraction.ZERO, l.getEntry(i, j));
}
}
}
/** test that U is upper triangular */
+ @Test
public void testUUpperTriangular() {
FieldMatrix matrix = new Array2DRowFieldMatrix(testData);
FieldMatrix u = new FieldLUDecompositionImpl(matrix).getU();
for (int i = 0; i < u.getRowDimension(); i++) {
for (int j = 0; j < i; j++) {
- assertEquals(Fraction.ZERO, u.getEntry(i, j));
+ Assert.assertEquals(Fraction.ZERO, u.getEntry(i, j));
}
}
}
/** test that P is a permutation matrix */
+ @Test
public void testPPermutation() {
FieldMatrix matrix = new Array2DRowFieldMatrix(testData);
FieldMatrix p = new FieldLUDecompositionImpl(matrix).getP();
@@ -177,9 +179,9 @@ public class FieldLUDecompositionImplTest extends TestCase {
++otherCount;
}
}
- assertEquals(p.getColumnDimension() - 1, zeroCount);
- assertEquals(1, oneCount);
- assertEquals(0, otherCount);
+ Assert.assertEquals(p.getColumnDimension() - 1, zeroCount);
+ Assert.assertEquals(1, oneCount);
+ Assert.assertEquals(0, otherCount);
}
for (int j = 0; j < p.getColumnDimension(); j++) {
@@ -196,26 +198,28 @@ public class FieldLUDecompositionImplTest extends TestCase {
++otherCount;
}
}
- assertEquals(p.getRowDimension() - 1, zeroCount);
- assertEquals(1, oneCount);
- assertEquals(0, otherCount);
+ Assert.assertEquals(p.getRowDimension() - 1, zeroCount);
+ Assert.assertEquals(1, oneCount);
+ Assert.assertEquals(0, otherCount);
}
}
/** test singular */
+ @Test
public void testSingular() {
FieldLUDecomposition lu =
new FieldLUDecompositionImpl(new Array2DRowFieldMatrix(testData));
- assertTrue(lu.getSolver().isNonSingular());
+ Assert.assertTrue(lu.getSolver().isNonSingular());
lu = new FieldLUDecompositionImpl(new Array2DRowFieldMatrix(singular));
- assertFalse(lu.getSolver().isNonSingular());
+ Assert.assertFalse(lu.getSolver().isNonSingular());
lu = new FieldLUDecompositionImpl(new Array2DRowFieldMatrix(bigSingular));
- assertFalse(lu.getSolver().isNonSingular());
+ Assert.assertFalse(lu.getSolver().isNonSingular());
}
/** test matrices values */
+ @Test
public void testMatricesValues1() {
FieldLUDecomposition lu =
new FieldLUDecompositionImpl(new Array2DRowFieldMatrix(testData));
@@ -245,17 +249,18 @@ public class FieldLUDecompositionImplTest extends TestCase {
TestUtils.assertEquals(pRef, p);
int[] pivot = lu.getPivot();
for (int i = 0; i < pivotRef.length; ++i) {
- assertEquals(pivotRef[i], pivot[i]);
+ Assert.assertEquals(pivotRef[i], pivot[i]);
}
// check the same cached instance is returned the second time
- assertTrue(l == lu.getL());
- assertTrue(u == lu.getU());
- assertTrue(p == lu.getP());
+ Assert.assertTrue(l == lu.getL());
+ Assert.assertTrue(u == lu.getU());
+ Assert.assertTrue(p == lu.getP());
}
/** test matrices values */
+ @Test
public void testMatricesValues2() {
FieldLUDecomposition lu =
new FieldLUDecompositionImpl(new Array2DRowFieldMatrix(luData));
@@ -285,14 +290,12 @@ public class FieldLUDecompositionImplTest extends TestCase {
TestUtils.assertEquals(pRef, p);
int[] pivot = lu.getPivot();
for (int i = 0; i < pivotRef.length; ++i) {
- assertEquals(pivotRef[i], pivot[i]);
+ Assert.assertEquals(pivotRef[i], pivot[i]);
}
// check the same cached instance is returned the second time
- assertTrue(l == lu.getL());
- assertTrue(u == lu.getU());
- assertTrue(p == lu.getP());
-
+ Assert.assertTrue(l == lu.getL());
+ Assert.assertTrue(u == lu.getU());
+ Assert.assertTrue(p == lu.getP());
}
-
}
diff --git a/src/test/java/org/apache/commons/math/linear/FieldMatrixImplTest.java b/src/test/java/org/apache/commons/math/linear/FieldMatrixImplTest.java
index e4487428e..d81a15995 100644
--- a/src/test/java/org/apache/commons/math/linear/FieldMatrixImplTest.java
+++ b/src/test/java/org/apache/commons/math/linear/FieldMatrixImplTest.java
@@ -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.TestUtils;
import org.apache.commons.math.fraction.Fraction;
@@ -24,13 +25,11 @@ import org.apache.commons.math.fraction.FractionField;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.exception.MathIllegalStateException;
import org.apache.commons.math.exception.DimensionMismatchException;
-import org.apache.commons.math.exception.MatrixDimensionMismatchException;
import org.apache.commons.math.exception.NoDataException;
import org.apache.commons.math.exception.OutOfRangeException;
import org.apache.commons.math.exception.NumberIsTooSmallException;
import org.apache.commons.math.exception.NotStrictlyPositiveException;
import org.apache.commons.math.exception.NullArgumentException;
-import org.apache.commons.math.exception.NonSquareMatrixException;
import org.apache.commons.math.exception.MathIllegalArgumentException;
/**
@@ -39,7 +38,7 @@ import org.apache.commons.math.exception.MathIllegalArgumentException;
* @version $Revision$ $Date$
*/
-public final class FieldMatrixImplTest extends TestCase {
+public final class FieldMatrixImplTest {
// 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)} };
@@ -101,33 +100,32 @@ public final class FieldMatrixImplTest extends TestCase {
protected double entryTolerance = 10E-16;
protected double normTolerance = 10E-14;
- public FieldMatrixImplTest(String name) {
- super(name);
- }
-
/** test dimensions */
+ @Test
public void testDimensions() {
Array2DRowFieldMatrix m = new Array2DRowFieldMatrix(testData);
Array2DRowFieldMatrix m2 = new Array2DRowFieldMatrix(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() {
Array2DRowFieldMatrix m1 = new Array2DRowFieldMatrix(testData);
Array2DRowFieldMatrix m2 = new Array2DRowFieldMatrix(m1.getData());
- assertEquals(m2,m1);
+ Assert.assertEquals(m2,m1);
Array2DRowFieldMatrix m3 = new Array2DRowFieldMatrix(testData);
Array2DRowFieldMatrix m4 = new Array2DRowFieldMatrix(m3.getData(), false);
- assertEquals(m4,m3);
+ Assert.assertEquals(m4,m3);
}
/** test add */
+ @Test
public void testAdd() {
Array2DRowFieldMatrix m = new Array2DRowFieldMatrix(testData);
Array2DRowFieldMatrix mInv = new Array2DRowFieldMatrix(testDataInv);
@@ -135,37 +133,40 @@ public final class FieldMatrixImplTest extends TestCase {
Fraction[][] sumEntries = mPlusMInv.getData();
for (int row = 0; row < m.getRowDimension(); row++) {
for (int col = 0; col < m.getColumnDimension(); col++) {
- assertEquals(testDataPlusInv[row][col],sumEntries[row][col]);
+ Assert.assertEquals(testDataPlusInv[row][col],sumEntries[row][col]);
}
}
}
/** test add failure */
+ @Test
public void testAddFail() {
Array2DRowFieldMatrix m = new Array2DRowFieldMatrix(testData);
Array2DRowFieldMatrix m2 = new Array2DRowFieldMatrix(testData2);
try {
m.add(m2);
- fail("MathIllegalArgumentException expected");
+ Assert.fail("MathIllegalArgumentException expected");
} catch (MathIllegalArgumentException ex) {
// ignored
}
}
/** test m-n = m + -n */
+ @Test
public void testPlusMinus() {
Array2DRowFieldMatrix m = new Array2DRowFieldMatrix(testData);
Array2DRowFieldMatrix m2 = new Array2DRowFieldMatrix(testDataInv);
TestUtils.assertEquals(m.subtract(m2),m2.scalarMultiply(new Fraction(-1)).add(m));
try {
m.subtract(new Array2DRowFieldMatrix(testData2));
- fail("Expecting illegalArgumentException");
+ Assert.fail("Expecting illegalArgumentException");
} catch (MathIllegalArgumentException ex) {
// ignored
}
}
/** test multiply */
+ @Test
public void testMultiply() {
Array2DRowFieldMatrix m = new Array2DRowFieldMatrix(testData);
Array2DRowFieldMatrix mInv = new Array2DRowFieldMatrix(testDataInv);
@@ -178,7 +179,7 @@ public final class FieldMatrixImplTest extends TestCase {
TestUtils.assertEquals(m2.multiply(identity), m2);
try {
m.multiply(new Array2DRowFieldMatrix(bigSingular));
- fail("Expecting illegalArgumentException");
+ Assert.fail("Expecting illegalArgumentException");
} catch (MathIllegalArgumentException ex) {
// ignored
}
@@ -190,6 +191,7 @@ public final class FieldMatrixImplTest extends TestCase {
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 m3 = new Array2DRowFieldMatrix