commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From billbar...@apache.org
Subject svn commit: r775787 - in /commons/proper/math/trunk/src/test/org/apache/commons/math/linear: SparseRealMatrixTest.java SparseRealVectorTest.java
Date Mon, 18 May 2009 01:05:40 GMT
Author: billbarker
Date: Mon May 18 01:05:39 2009
New Revision: 775787

URL: http://svn.apache.org/viewvc?rev=775787&view=rev
Log:
Ok, so laking add/subtract tests now.  I'll try to add later, but checking in the existing
tests so that [math] will at least build.

Modified:
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealMatrixTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealVectorTest.java

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealMatrixTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealMatrixTest.java?rev=775787&r1=775786&r2=775787&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealMatrixTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealMatrixTest.java
Mon May 18 01:05:39 2009
@@ -24,7 +24,7 @@
 import org.apache.commons.math.linear.decomposition.NonSquareMatrixException;
 
 /**
- * Test cases for the {@link SparseRealMatrix} class.
+ * Test cases for the {@link OpenMapRealMatrix} class.
  * 
  * @version $Revision$ $Date: 2008-11-07 06:48:13 -0800 (Fri, 07 Nov
  *          2008) $
@@ -117,8 +117,8 @@
 
     /** test dimensions */
     public void testDimensions() {
-        SparseRealMatrix m = createSparseMatrix(testData);
-        SparseRealMatrix m2 = createSparseMatrix(testData2);
+        OpenMapRealMatrix m = createSparseMatrix(testData);
+        OpenMapRealMatrix m2 = createSparseMatrix(testData2);
         assertEquals("testData row dimension", 3, m.getRowDimension());
         assertEquals("testData column dimension", 3, m.getColumnDimension());
         assertTrue("testData is square", m.isSquare());
@@ -129,21 +129,21 @@
 
     /** test copy functions */
     public void testCopyFunctions() {
-        SparseRealMatrix m1 = createSparseMatrix(testData);
+        OpenMapRealMatrix m1 = createSparseMatrix(testData);
         RealMatrix m2 = m1.copy();
-        assertTrue(m2 instanceof SparseRealMatrix);
+        assertTrue(m2 instanceof OpenMapRealMatrix);
         assertEquals((m2), m1);
-        SparseRealMatrix m3 = createSparseMatrix(testData);
+        OpenMapRealMatrix m3 = createSparseMatrix(testData);
         RealMatrix m4 = m3.copy();
-        assertTrue(m4 instanceof SparseRealMatrix);
+        assertTrue(m4 instanceof OpenMapRealMatrix);
         assertEquals((m4), m3);
     }
 
     /** test add */
     public void testAdd() {
-        SparseRealMatrix m = createSparseMatrix(testData);
-        SparseRealMatrix mInv = createSparseMatrix(testDataInv);
-        SparseRealMatrix mDataPlusInv = createSparseMatrix(testDataPlusInv);
+        OpenMapRealMatrix m = createSparseMatrix(testData);
+        OpenMapRealMatrix mInv = createSparseMatrix(testDataInv);
+        OpenMapRealMatrix mDataPlusInv = createSparseMatrix(testDataPlusInv);
         RealMatrix mPlusMInv = m.add(mInv);
         for (int row = 0; row < m.getRowDimension(); row++) {
             for (int col = 0; col < m.getColumnDimension(); col++) {
@@ -156,8 +156,8 @@
 
     /** test add failure */
     public void testAddFail() {
-        SparseRealMatrix m = createSparseMatrix(testData);
-        SparseRealMatrix m2 = createSparseMatrix(testData2);
+        OpenMapRealMatrix m = createSparseMatrix(testData);
+        OpenMapRealMatrix m2 = createSparseMatrix(testData2);
         try {
             m.add(m2);
             fail("IllegalArgumentException expected");
@@ -168,16 +168,16 @@
 
     /** test norm */
     public void testNorm() {
-        SparseRealMatrix m = createSparseMatrix(testData);
-        SparseRealMatrix m2 = createSparseMatrix(testData2);
+        OpenMapRealMatrix m = createSparseMatrix(testData);
+        OpenMapRealMatrix m2 = createSparseMatrix(testData2);
         assertEquals("testData norm", 14d, m.getNorm(), entryTolerance);
         assertEquals("testData2 norm", 7d, m2.getNorm(), entryTolerance);
     }
 
     /** test m-n = m + -n */
     public void testPlusMinus() {
-        SparseRealMatrix m = createSparseMatrix(testData);
-        SparseRealMatrix n = createSparseMatrix(testDataInv);
+        OpenMapRealMatrix m = createSparseMatrix(testData);
+        OpenMapRealMatrix n = createSparseMatrix(testDataInv);
         assertClose("m-n = m + -n", m.subtract(n),
             n.scalarMultiply(-1d).add(m), entryTolerance);
         try {
@@ -190,10 +190,10 @@
 
     /** test multiply */
     public void testMultiply() {
-        SparseRealMatrix m = createSparseMatrix(testData);
-        SparseRealMatrix mInv = createSparseMatrix(testDataInv);
-        SparseRealMatrix identity = createSparseMatrix(id);
-        SparseRealMatrix m2 = createSparseMatrix(testData2);
+        OpenMapRealMatrix m = createSparseMatrix(testData);
+        OpenMapRealMatrix mInv = createSparseMatrix(testDataInv);
+        OpenMapRealMatrix identity = createSparseMatrix(id);
+        OpenMapRealMatrix m2 = createSparseMatrix(testData2);
         assertClose("inverse multiply", m.multiply(mInv), identity,
                 entryTolerance);
         assertClose("inverse multiply", m.multiply(new DenseRealMatrix(testDataInv)), identity,
@@ -308,9 +308,9 @@
         RealMatrix m5 = createSparseMatrix(d5);
         assertClose("m3*m4=m5", m4.preMultiply(m3), m5, entryTolerance);
 
-        SparseRealMatrix m = createSparseMatrix(testData);
-        SparseRealMatrix mInv = createSparseMatrix(testDataInv);
-        SparseRealMatrix identity = createSparseMatrix(id);
+        OpenMapRealMatrix m = createSparseMatrix(testData);
+        OpenMapRealMatrix mInv = createSparseMatrix(testDataInv);
+        OpenMapRealMatrix identity = createSparseMatrix(id);
         assertClose("inverse multiply", m.preMultiply(mInv), identity,
                 entryTolerance);
         assertClose("inverse multiply", mInv.preMultiply(m), identity,
@@ -542,9 +542,9 @@
     }
 
     public void testEqualsAndHashCode() {
-        SparseRealMatrix m = createSparseMatrix(testData);
-        SparseRealMatrix m1 = (SparseRealMatrix) m.copy();
-        SparseRealMatrix mt = (SparseRealMatrix) m.transpose();
+        OpenMapRealMatrix m = createSparseMatrix(testData);
+        OpenMapRealMatrix m1 = (OpenMapRealMatrix) m.copy();
+        OpenMapRealMatrix mt = (OpenMapRealMatrix) m.transpose();
         assertTrue(m.hashCode() != mt.hashCode());
         assertEquals(m.hashCode(), m1.hashCode());
         assertEquals(m, m);
@@ -555,15 +555,15 @@
     }
 
     public void testToString() {
-        SparseRealMatrix m = createSparseMatrix(testData);
-        assertEquals("SparseRealMatrix{{1.0,2.0,3.0},{2.0,5.0,3.0},{1.0,0.0,8.0}}", 
+        OpenMapRealMatrix m = createSparseMatrix(testData);
+        assertEquals("OpenMapRealMatrix{{1.0,2.0,3.0},{2.0,5.0,3.0},{1.0,0.0,8.0}}", 
             m.toString());
-        m = new SparseRealMatrix(1, 1);
-        assertEquals("SparseRealMatrix{{0.0}}", m.toString());
+        m = new OpenMapRealMatrix(1, 1);
+        assertEquals("OpenMapRealMatrix{{0.0}}", m.toString());
     }
 
     public void testSetSubMatrix() throws Exception {
-        SparseRealMatrix m = createSparseMatrix(testData);
+        OpenMapRealMatrix m = createSparseMatrix(testData);
         m.setSubMatrix(detData2, 1, 1);
         RealMatrix expected = createSparseMatrix(new double[][] {
                 { 1.0, 2.0, 3.0 }, { 2.0, 1.0, 3.0 }, { 1.0, 2.0, 4.0 } });
@@ -580,7 +580,7 @@
         assertEquals(expected, m);
 
         // javadoc example
-        SparseRealMatrix matrix = 
+        OpenMapRealMatrix matrix = 
             createSparseMatrix(new double[][] { 
         { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 0, 1, 2 } });
         matrix.setSubMatrix(new double[][] { { 3, 4 }, { 5, 6 } }, 1, 1);
@@ -617,7 +617,7 @@
             // expected
         }
         try {
-            new SparseRealMatrix(0, 0);
+            new OpenMapRealMatrix(0, 0);
             fail("expecting IllegalArgumentException");
         } catch (IllegalArgumentException e) {
             // expected
@@ -661,8 +661,8 @@
         }
     }
     
-    private SparseRealMatrix createSparseMatrix(double[][] data) {
-        SparseRealMatrix matrix = new SparseRealMatrix(data.length, data[0].length);
+    private OpenMapRealMatrix createSparseMatrix(double[][] data) {
+        OpenMapRealMatrix matrix = new OpenMapRealMatrix(data.length, data[0].length);
         for (int row = 0; row < data.length; row++) {
             for (int col = 0; col < data[row].length; col++) {
                 matrix.setEntry(row, col, data[row][col]);

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealVectorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealVectorTest.java?rev=775787&r1=775786&r2=775787&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealVectorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SparseRealVectorTest.java
Mon May 18 01:05:39 2009
@@ -22,7 +22,7 @@
 import junit.framework.TestSuite;
 
 /**
- * Test cases for the {@link SparseRealVector} class.
+ * Test cases for the {@link OpenMapRealVector} class.
  *
  * @version $Revision: 728186 $ $Date$
  */
@@ -101,7 +101,7 @@
             for (int i = 0; i < data.length; i++) {
                 out[i] = data[i] * d;
             }
-            return new SparseRealVector(out);
+            return new OpenMapRealVector(out);
         }
 
         public RealVector mapMultiplyToSelf(double d) {
@@ -466,14 +466,14 @@
 
     public void testConstructors() {
 
-        SparseRealVector v0 = new SparseRealVector();
+        OpenMapRealVector v0 = new OpenMapRealVector();
         assertEquals("testData len", 0, v0.getDimension());
 
-        SparseRealVector v1 = new SparseRealVector(7);
+        OpenMapRealVector v1 = new OpenMapRealVector(7);
         assertEquals("testData len", 7, v1.getDimension());
         assertEquals("testData is 0.0 ", 0.0, v1.getEntry(6));
 
-        SparseRealVector v3 = new SparseRealVector(vec1);
+        OpenMapRealVector v3 = new OpenMapRealVector(vec1);
         assertEquals("testData len", 3, v3.getDimension());
         assertEquals("testData is 2.0 ", 2.0, v3.getEntry(1));
 
@@ -489,25 +489,25 @@
         //    fail("wrong exception caught");
         //}
 
-        RealVector v5_i = new SparseRealVector(dvec1);
+        RealVector v5_i = new OpenMapRealVector(dvec1);
         assertEquals("testData len", 9, v5_i.getDimension());
         assertEquals("testData is 9.0 ", 9.0, v5_i.getEntry(8));
 
-        SparseRealVector v5 = new SparseRealVector(dvec1);
+        OpenMapRealVector v5 = new OpenMapRealVector(dvec1);
         assertEquals("testData len", 9, v5.getDimension());
         assertEquals("testData is 9.0 ", 9.0, v5.getEntry(8));
 
-        SparseRealVector v7 = new SparseRealVector(v1);
+        OpenMapRealVector v7 = new OpenMapRealVector(v1);
         assertEquals("testData len", 7, v7.getDimension());
         assertEquals("testData is 0.0 ", 0.0, v7.getEntry(6));
 
         SparseRealVectorTestImpl v7_i = new SparseRealVectorTestImpl(vec1);
 
-        SparseRealVector v7_2 = new SparseRealVector(v7_i);
+        OpenMapRealVector v7_2 = new OpenMapRealVector(v7_i);
         assertEquals("testData len", 3, v7_2.getDimension());
         assertEquals("testData is 0.0 ", 2.0d, v7_2.getEntry(1));
 
-        SparseRealVector v8 = new SparseRealVector(v1);
+        OpenMapRealVector v8 = new OpenMapRealVector(v1);
         assertEquals("testData len", 7, v8.getDimension());
         assertEquals("testData is 0.0 ", 0.0, v8.getEntry(6));
 
@@ -515,9 +515,9 @@
 
     public void testDataInOut() {
 
-        SparseRealVector v1 = new SparseRealVector(vec1);
-        SparseRealVector v2 = new SparseRealVector(vec2);
-        SparseRealVector v4 = new SparseRealVector(vec4);
+        OpenMapRealVector v1 = new OpenMapRealVector(vec1);
+        OpenMapRealVector v2 = new OpenMapRealVector(vec2);
+        OpenMapRealVector v4 = new OpenMapRealVector(vec4);
         SparseRealVectorTestImpl v2_t = new SparseRealVectorTestImpl(vec2); 
 
         RealVector v_append_1 = v1.append(v2);
@@ -548,7 +548,7 @@
             fail("wrong exception caught");
         }
 
-        SparseRealVector v_set1 = (SparseRealVector) v1.copy();
+        OpenMapRealVector v_set1 = (OpenMapRealVector) v1.copy();
         v_set1.setEntry(1, 11.0);
         assertEquals("testData is 11.0 ", 11.0, v_set1.getEntry(1));
         try {
@@ -560,7 +560,7 @@
             fail("wrong exception caught");
         }
 
-        SparseRealVector v_set2 = (SparseRealVector) v4.copy();
+        OpenMapRealVector v_set2 = (OpenMapRealVector) v4.copy();
         v_set2.setSubVector(3, v1);
         assertEquals("testData is 1.0 ", 1.0, v_set2.getEntry(3));
         assertEquals("testData is 7.0 ", 7.0, v_set2.getEntry(6));
@@ -573,7 +573,7 @@
             fail("wrong exception caught");
         }
 
-        SparseRealVector v_set3 = (SparseRealVector) v1.copy();
+        OpenMapRealVector v_set3 = (OpenMapRealVector) v1.copy();
         v_set3.set(13.0);
         assertEquals("testData is 13.0 ", 13.0, v_set3.getEntry(2));
 
@@ -586,7 +586,7 @@
             fail("wrong exception caught");
         }
 
-        SparseRealVector v_set4 = (SparseRealVector) v4.copy();
+        OpenMapRealVector v_set4 = (OpenMapRealVector) v4.copy();
         v_set4.setSubVector(3, v2_t);
         assertEquals("testData is 1.0 ", 4.0, v_set4.getEntry(3));
         assertEquals("testData is 7.0 ", 7.0, v_set4.getEntry(6));
@@ -603,7 +603,7 @@
     }
 
     public void testMapFunctions() { 
-        SparseRealVector v1 = new SparseRealVector(vec1);
+        OpenMapRealVector v1 = new OpenMapRealVector(vec1);
 
         //octave =  v1 .+ 2.0
         RealVector v_mapAdd = v1.mapAdd(2.0d);
@@ -783,7 +783,7 @@
         assertClose("compare vectors" ,result_mapTanToSelf,v_mapTanToSelf.getData(),normTolerance);
 
         double[] vat_a = {0d, 0.5d, 1.0d};
-        SparseRealVector vat = new SparseRealVector(vat_a);
+        OpenMapRealVector vat = new OpenMapRealVector(vat_a);
 
         //octave =  acos(vat)
         RealVector v_mapAcos = vat.mapAcos();
@@ -830,7 +830,7 @@
         assertClose("compare vectors" ,result_mapInvToSelf,v_mapInvToSelf.getData(),normTolerance);
 
         double[] abs_a = {-1.0d, 0.0d, 1.0d};
-        SparseRealVector abs_v = new SparseRealVector(abs_a);
+        OpenMapRealVector abs_v = new OpenMapRealVector(abs_a);
 
         //octave =  abs(abs_v)
         RealVector v_mapAbs = abs_v.mapAbs();
@@ -855,7 +855,7 @@
         assertClose("compare vectors" ,result_mapSqrtToSelf,v_mapSqrtToSelf.getData(),normTolerance);
 
         double[] cbrt_a = {-2.0d, 0.0d, 2.0d};
-        SparseRealVector cbrt_v = new SparseRealVector(cbrt_a);
+        OpenMapRealVector cbrt_v = new OpenMapRealVector(cbrt_a);
 
         //octave =  ???
         RealVector v_mapCbrt = cbrt_v.mapCbrt();
@@ -869,7 +869,7 @@
         assertClose("compare vectors" ,result_mapCbrtToSelf,v_mapCbrtToSelf.getData(),normTolerance);
 
         double[] ceil_a = {-1.1d, 0.9d, 1.1d};
-        SparseRealVector ceil_v = new SparseRealVector(ceil_a);
+        OpenMapRealVector ceil_v = new OpenMapRealVector(ceil_a);
 
         //octave =  ceil(ceil_v)
         RealVector v_mapCeil = ceil_v.mapCeil();
@@ -931,9 +931,9 @@
     }
 
     public void testBasicFunctions() { 
-        SparseRealVector v1 = new SparseRealVector(vec1);
-        SparseRealVector v2 = new SparseRealVector(vec2);
-        SparseRealVector v_null = new SparseRealVector(vec_null);
+        OpenMapRealVector v1 = new OpenMapRealVector(vec1);
+        OpenMapRealVector v2 = new OpenMapRealVector(vec2);
+        OpenMapRealVector v_null = new OpenMapRealVector(vec_null);
 
         SparseRealVectorTestImpl v2_t = new SparseRealVectorTestImpl(vec2); 
 
@@ -970,7 +970,7 @@
         assertEquals("compare values  ",3d, d_getLInfDistance_2 );
 
         //octave =  v1 + v2
-        SparseRealVector v_add = v1.add(v2);
+        OpenMapRealVector v_add = v1.add(v2);
         double[] result_add = {5d, 7d, 9d};
         assertClose("compare vect" ,v_add.getData(),result_add,normTolerance);
 
@@ -980,7 +980,7 @@
         assertClose("compare vect" ,v_add_i.getData(),result_add_i,normTolerance);
 
         //octave =  v1 - v2
-        SparseRealVector v_subtract = v1.subtract(v2);
+        OpenMapRealVector v_subtract = v1.subtract(v2);
         double[] result_subtract = {-3d, -3d, -3d};
         assertClose("compare vect" ,v_subtract.getData(),result_subtract,normTolerance);
 
@@ -1033,7 +1033,7 @@
             fail("wrong exception caught");
         }
 
-        SparseRealVector v_unitize = (SparseRealVector)v1.copy();
+        OpenMapRealVector v_unitize = (OpenMapRealVector)v1.copy();
         v_unitize.unitize();
         assertClose("compare vect" ,v_unitVector_2.getData(),v_unitize.getData(),normTolerance);
         try {
@@ -1056,7 +1056,7 @@
     }  
 
     public void testMisc() { 
-        SparseRealVector v1 = new SparseRealVector(vec1);
+        OpenMapRealVector v1 = new OpenMapRealVector(vec1);
 
         String out1 = v1.toString();
         assertTrue("some output ",  out1.length()!=0);
@@ -1074,7 +1074,7 @@
 
     public void testPredicates() {
 
-        SparseRealVector v = new SparseRealVector(new double[] { 0, 1, 2 });
+        OpenMapRealVector v = new OpenMapRealVector(new double[] { 0, 1, 2 });
 
         assertFalse(v.isNaN());
         v.setEntry(1, Double.NaN);
@@ -1087,9 +1087,9 @@
         assertTrue(v.isInfinite());
 
         v.setEntry(0, 0);
-        assertEquals(v, new SparseRealVector(new double[] { 0, 1, 2 }));
-        assertNotSame(v, new SparseRealVector(new double[] { 0, 1, 2 + Math.ulp(2)}));
-        assertNotSame(v, new SparseRealVector(new double[] { 0, 1, 2, 3 }));
+        assertEquals(v, new OpenMapRealVector(new double[] { 0, 1, 2 }));
+        assertNotSame(v, new OpenMapRealVector(new double[] { 0, 1, 2 + Math.ulp(2)}));
+        assertNotSame(v, new OpenMapRealVector(new double[] { 0, 1, 2, 3 }));
 
     }
 



Mime
View raw message