Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 5439 invoked from network); 20 Apr 2009 20:54:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 20 Apr 2009 20:54:09 -0000 Received: (qmail 40836 invoked by uid 500); 20 Apr 2009 20:54:09 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 40746 invoked by uid 500); 20 Apr 2009 20:54:09 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 40737 invoked by uid 99); 20 Apr 2009 20:54:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Apr 2009 20:54:08 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Apr 2009 20:54:07 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8702A23889D9; Mon, 20 Apr 2009 20:53:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r766867 - /commons/proper/math/trunk/src/test/org/apache/commons/math/linear/MatrixUtilsTest.java Date: Mon, 20 Apr 2009 20:53:47 -0000 To: commits@commons.apache.org From: luc@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090420205347.8702A23889D9@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: luc Date: Mon Apr 20 20:53:46 2009 New Revision: 766867 URL: http://svn.apache.org/viewvc?rev=766867&view=rev Log: deprecated tests for deprecated methods added new tests Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/MatrixUtilsTest.java Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/MatrixUtilsTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/MatrixUtilsTest.java?rev=766867&r1=766866&r2=766867&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/MatrixUtilsTest.java (original) +++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/MatrixUtilsTest.java Mon Apr 20 20:53:46 2009 @@ -21,6 +21,10 @@ import junit.framework.TestCase; import junit.framework.TestSuite; +import org.apache.commons.math.fraction.Fraction; +import org.apache.commons.math.fraction.FractionConversionException; +import org.apache.commons.math.fraction.FractionField; + /** * Test cases for the {@link MatrixUtils} class. * @@ -35,19 +39,27 @@ protected BigDecimal[] bigRow = {new BigDecimal(1),new BigDecimal(2),new BigDecimal(3)}; protected String[] stringRow = {"1", "2", "3"}; + protected Fraction[] fractionRow = + {new Fraction(1),new Fraction(2),new Fraction(3)}; protected double[][] rowMatrix = {{1,2,3}}; protected BigDecimal[][] bigRowMatrix = {{new BigDecimal(1), new BigDecimal(2), new BigDecimal(3)}}; protected String[][] stringRowMatrix = {{"1", "2", "3"}}; + protected Fraction[][] fractionRowMatrix = + {{new Fraction(1), new Fraction(2), new Fraction(3)}}; protected double[] col = {0,4,6}; protected BigDecimal[] bigCol = {new BigDecimal(0),new BigDecimal(4),new BigDecimal(6)}; protected String[] stringCol = {"0","4","6"}; + protected Fraction[] fractionCol = + {new Fraction(0),new Fraction(4),new Fraction(6)}; protected double[] nullDoubleArray = null; protected double[][] colMatrix = {{0},{4},{6}}; protected BigDecimal[][] bigColMatrix = {{new BigDecimal(0)},{new BigDecimal(4)},{new BigDecimal(6)}}; protected String[][] stringColMatrix = {{"0"}, {"4"}, {"6"}}; + protected Fraction[][] fractionColMatrix = + {{new Fraction(0)},{new Fraction(4)},{new Fraction(6)}}; public MatrixUtilsTest(String name) { super(name); @@ -82,7 +94,33 @@ // expected } } - + + public void testcreateFieldMatrix() { + assertEquals(new FieldMatrixImpl(asFraction(testData)), + MatrixUtils.createFieldMatrix(asFraction(testData))); + assertEquals(new FieldMatrixImpl(fractionColMatrix), + MatrixUtils.createFieldMatrix(fractionColMatrix)); + try { + MatrixUtils.createFieldMatrix(asFraction(new double[][] {{1}, {1,2}})); // ragged + fail("Expecting IllegalArgumentException"); + } catch (IllegalArgumentException ex) { + // expected + } + try { + MatrixUtils.createFieldMatrix(asFraction(new double[][] {{}, {}})); // no columns + fail("Expecting IllegalArgumentException"); + } catch (IllegalArgumentException ex) { + // expected + } + try { + MatrixUtils.createFieldMatrix((Fraction[][])null); // null + fail("Expecting NullPointerException"); + } catch (NullPointerException ex) { + // expected + } + } + + @Deprecated public void testCreateBigMatrix() { assertEquals(new BigMatrixImpl(testData), MatrixUtils.createBigMatrix(testData)); @@ -131,6 +169,26 @@ } } + public void testCreateRowFieldMatrix() { + assertEquals(MatrixUtils.createRowFieldMatrix(asFraction(row)), + new FieldMatrixImpl(asFraction(rowMatrix))); + assertEquals(MatrixUtils.createRowFieldMatrix(fractionRow), + new FieldMatrixImpl(fractionRowMatrix)); + try { + MatrixUtils.createRowFieldMatrix(new Fraction[] {}); // empty + fail("Expecting IllegalArgumentException"); + } catch (IllegalArgumentException ex) { + // expected + } + try { + MatrixUtils.createRowFieldMatrix((Fraction[]) null); // null + fail("Expecting NullPointerException"); + } catch (NullPointerException ex) { + // expected + } + } + + @Deprecated public void testCreateRowBigMatrix() { assertEquals(MatrixUtils.createRowBigMatrix(row), new BigMatrixImpl(rowMatrix)); @@ -151,7 +209,7 @@ // expected } } - + public void testCreateColumnRealMatrix() { assertEquals(MatrixUtils.createColumnRealMatrix(col), new DenseRealMatrix(colMatrix)); @@ -169,6 +227,27 @@ } } + public void testCreateColumnFieldMatrix() { + assertEquals(MatrixUtils.createColumnFieldMatrix(asFraction(col)), + new FieldMatrixImpl(asFraction(colMatrix))); + assertEquals(MatrixUtils.createColumnFieldMatrix(fractionCol), + new FieldMatrixImpl(fractionColMatrix)); + + try { + MatrixUtils.createColumnFieldMatrix(new Fraction[] {}); // empty + fail("Expecting IllegalArgumentException"); + } catch (IllegalArgumentException ex) { + // expected + } + try { + MatrixUtils.createColumnFieldMatrix((Fraction[]) null); // null + fail("Expecting NullPointerException"); + } catch (NullPointerException ex) { + // expected + } + } + + @Deprecated public void testCreateColumnBigMatrix() { assertEquals(MatrixUtils.createColumnBigMatrix(col), new BigMatrixImpl(colMatrix)); @@ -190,7 +269,7 @@ // expected } } - + /** * Verifies that the matrix is an identity matrix */ @@ -220,6 +299,62 @@ /** * Verifies that the matrix is an identity matrix */ + protected void checkIdentityFieldMatrix(FieldMatrix m) { + for (int i = 0; i < m.getRowDimension(); i++) { + for (int j =0; j < m.getColumnDimension(); j++) { + if (i == j) { + assertEquals(m.getEntry(i, j), Fraction.ONE); + } else { + assertEquals(m.getEntry(i, j), Fraction.ZERO); + } + } + } + } + + public void testcreateFieldIdentityMatrix() { + checkIdentityFieldMatrix(MatrixUtils.createFieldIdentityMatrix(FractionField.getInstance(), 3)); + checkIdentityFieldMatrix(MatrixUtils.createFieldIdentityMatrix(FractionField.getInstance(), 2)); + checkIdentityFieldMatrix(MatrixUtils.createFieldIdentityMatrix(FractionField.getInstance(), 1)); + try { + MatrixUtils.createRealIdentityMatrix(0); + } catch (IllegalArgumentException ex) { + // expected + } + } + + public static final Fraction[][] asFraction(double[][] data) { + Fraction d[][] = new Fraction[data.length][]; + try { + for (int i = 0; i < data.length; ++i) { + double[] dataI = data[i]; + Fraction[] dI = new Fraction[dataI.length]; + for (int j = 0; j < dataI.length; ++j) { + dI[j] = new Fraction(dataI[j]); + } + d[i] = dI; + } + } catch (FractionConversionException fce) { + fail(fce.getMessage()); + } + return d; + } + + public static final Fraction[] asFraction(double[] data) { + Fraction d[] = new Fraction[data.length]; + try { + for (int i = 0; i < data.length; ++i) { + d[i] = new Fraction(data[i]); + } + } catch (FractionConversionException fce) { + fail(fce.getMessage()); + } + return d; + } + + /** + * Verifies that the matrix is an identity matrix + */ + @Deprecated protected void checkIdentityBigMatrix(BigMatrix m) { for (int i = 0; i < m.getRowDimension(); i++) { for (int j =0; j < m.getColumnDimension(); j++) { @@ -231,7 +366,8 @@ } } } - + + @Deprecated public void testCreateBigIdentityMatrix() { checkIdentityBigMatrix(MatrixUtils.createBigIdentityMatrix(3)); checkIdentityBigMatrix(MatrixUtils.createBigIdentityMatrix(2)); @@ -242,6 +378,6 @@ // expected } } - + }