Index: lutinmatrix/src/test/org/codelutin/math/matrix/BasicMatrixTest.java diff -u lutinmatrix/src/test/org/codelutin/math/matrix/BasicMatrixTest.java:1.4 lutinmatrix/src/test/org/codelutin/math/matrix/BasicMatrixTest.java:1.5 --- lutinmatrix/src/test/org/codelutin/math/matrix/BasicMatrixTest.java:1.4 Wed Oct 5 20:25:05 2005 +++ lutinmatrix/src/test/org/codelutin/math/matrix/BasicMatrixTest.java Thu Oct 20 20:58:04 2005 @@ -23,9 +23,9 @@ * Created: 27 oct. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * - * Mise a jour: $Date: 2005/10/05 20:25:05 $ + * Mise a jour: $Date: 2005/10/20 20:58:04 $ * par : $Author: bpoussin $ */ @@ -37,34 +37,38 @@ public class BasicMatrixTest extends TestCase { // BasicMatrixTest + public MatrixFactory getFactory() throws Exception { + return MatrixFactory.getInstance(); + } + public void testNew() throws Exception { BasicMatrix mat = null; try{ - mat = new BasicMatrix(null); + mat = new BasicMatrix(getFactory(), null); assertFalse(true); // on ne doit pas etre ici }catch(NullPointerException eee){ assertTrue(true); // mais on doit etre la } try{ - mat = new BasicMatrix(new int[]{0}); + mat = new BasicMatrix(getFactory(), new int[]{0}); assertFalse(true); // on ne doit pas etre ici }catch(IllegalArgumentException eee){ assertTrue(true); // mais on doit etre la } - mat = new BasicMatrix(new int[]{100}); - mat = new BasicMatrix(new int[]{10,1}); - mat = new BasicMatrix(new int[]{10,10,10,10}); + mat = new BasicMatrix(getFactory(), new int[]{100}); + mat = new BasicMatrix(getFactory(), new int[]{10,1}); + mat = new BasicMatrix(getFactory(), new int[]{10,10,10,10}); try{ - mat = new BasicMatrix(new int[]{-10}); + mat = new BasicMatrix(getFactory(), new int[]{-10}); assertFalse(true); // on ne doit pas etre ici }catch(IllegalArgumentException eee){ assertTrue(true); // mais on doit etre la } try{ - mat = new BasicMatrix(new int[]{10, 20, -10, 20}); + mat = new BasicMatrix(getFactory(), new int[]{10, 20, -10, 20}); assertFalse(true); // on ne doit pas etre ici }catch(IllegalArgumentException eee){ assertTrue(true); // mais on doit etre la @@ -73,7 +77,7 @@ public void testDimension()throws Exception { BasicMatrix mat = null; - mat = new BasicMatrix(new int[]{1,10,30,5}); + mat = new BasicMatrix(getFactory(), new int[]{1,10,30,5}); assertEquals(4, mat.getNbDim()); assertEquals(1, mat.getDim(0)); @@ -99,7 +103,7 @@ BasicMatrix mat = null; // test avec la plus petit BasicMatrix possible - mat = new BasicMatrix(new int[]{1}); + mat = new BasicMatrix(getFactory(), new int[]{1}); // test la valeur par defaut doit etre 0 assertEquals(0, mat.getValue(new int[]{0}), 0); mat.setValue(new int[]{0}, 30); @@ -113,7 +117,7 @@ assertTrue(true); // mais on doit etre la } - mat = new BasicMatrix(new int[]{1, 10, 5}); + mat = new BasicMatrix(getFactory(), new int[]{1, 10, 5}); mat.setValue(new int[]{0, 0, 0}, 0); mat.setValue(new int[]{0, 0, 1}, 1); mat.setValue(new int[]{0, 0, 2}, 2); @@ -146,8 +150,8 @@ } public void testEquals() throws Exception { - BasicMatrix m1 = new BasicMatrix(new int[]{3,3,3,3}); - BasicMatrix m2 = new BasicMatrix(new int[]{3,3,3,3}); + BasicMatrix m1 = new BasicMatrix(getFactory(), new int[]{3,3,3,3}); + BasicMatrix m2 = new BasicMatrix(getFactory(), new int[]{3,3,3,3}); assertEquals(m1, m2); @@ -193,7 +197,7 @@ }; int [][] val1 = new int[][]{{0}}; - BasicMatrix m1 = new BasicMatrix(new int[]{3,3,3}); + BasicMatrix m1 = new BasicMatrix(getFactory(), new int[]{3,3,3}); // System.out.println("Matrice a 27 valeurs"); int cpt = 0; for(BasicMatrixIterator iter = m1.iterator(); iter.next();){ @@ -204,7 +208,7 @@ assertEquals(27, cpt); cpt = 0; - BasicMatrix m2 = new BasicMatrix(new int[]{1}); + BasicMatrix m2 = new BasicMatrix(getFactory(), new int[]{1}); // System.out.println("Matrice a 1 valeurs"); for(BasicMatrixIterator iter = m2.iterator(); iter.next();){ Arrays.equals(val1[cpt], iter.getCoordinates()); @@ -214,24 +218,92 @@ assertEquals(1, cpt); } - public void testPerfLineaire() throws Exception { - MapFunction f = new MapFunction(){ - public float apply(float value){ - return value + 2; - } - }; + MapFunction f = new MapFunction(){ + public double apply(double value){ + return value + 2; + } + }; - BasicMatrix m1 = new BasicMatrix(new int[]{30,30,30,30}); + public void testPerfLineaire() throws Exception { + long time = System.nanoTime(); + BasicMatrix m1 = new BasicMatrix(getFactory(), new int[]{30,30,30,30}); m1.map(f); + long time1 = System.nanoTime(); + System.out.println("testPerfLineaire: " + (time1 - time)); } public void testPerfCoordonnee() throws Exception { - BasicMatrix m2 = new BasicMatrix(new int[]{30,30,30,30}); + long time = System.nanoTime(); + BasicMatrix m2 = new BasicMatrix(getFactory(), new int[]{30,30,30,30}); BasicMatrixIterator inc = m2.iterator(); while(inc.next()){ inc.setValue(inc.getValue() + 2); } + long time1 = System.nanoTime(); + System.out.println("testPerfCoordonnee: " + (time1 - time)); + + inc = m2.iterator(); + while(inc.next()){ + inc.setValue(inc.getValue() + 2); + } + long time2 = System.nanoTime(); + System.out.println("testPerfCoordonnee re: " + (time2 - time1)); + + m2.map(f); + long time3 = System.nanoTime(); + System.out.println("testPerfLineaire: " + (time3 - time2)); + + } + + public void testPerfCoordonnee2() throws Exception { + long time = System.nanoTime(); + BasicMatrix m2 = new BasicMatrix(getFactory(), new int[]{30,30,30,30}); + + BasicMatrixIterator inc = m2.iterator(); + while(inc.next() && inc.next()){ + inc.setValue(inc.getValue() + 2); + } + long time1 = System.nanoTime(); + System.out.println("testPerfCoordonnee2: " + (time1 - time)); + + inc = m2.iterator(); + while(inc.next() && inc.next()){ + inc.setValue(inc.getValue() + 2); + } + long time2 = System.nanoTime(); + System.out.println("testPerfCoordonnee2 re: " + (time2 - time1)); + + + m2.map(f); + long time3 = System.nanoTime(); + System.out.println("testPerfLineaire2: " + (time3 - time2)); + + } + + public void testPerfCoordonnee4() throws Exception { + long time = System.nanoTime(); + BasicMatrix m2 = new BasicMatrix(getFactory(), new int[]{30,30,30,30}); + + BasicMatrixIterator inc = m2.iterator(); + while(inc.next() && inc.next() && inc.next() && inc.next()){ + inc.setValue(inc.getValue() + 2); + } + long time1 = System.nanoTime(); + System.out.println("testPerfCoordonnee4: " + (time1 - time)); + + inc = m2.iterator(); + while(inc.next() && inc.next() && inc.next() && inc.next()){ + inc.setValue(inc.getValue() + 2); + } + long time2 = System.nanoTime(); + System.out.println("testPerfCoordonnee4 re: " + (time2 - time1)); + + + m2.map(f); + long time3 = System.nanoTime(); + System.out.println("testPerfLineaire4: " + (time3 - time2)); + } } // BasicMatrixTest Index: lutinmatrix/src/test/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java diff -u lutinmatrix/src/test/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java:1.3 lutinmatrix/src/test/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java:1.4 --- lutinmatrix/src/test/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java:1.3 Mon Nov 8 13:49:55 2004 +++ lutinmatrix/src/test/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java Thu Oct 20 20:58:04 2005 @@ -23,9 +23,9 @@ * Created: 31 oct. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Mise a jour: $Date: 2004/11/08 13:49:55 $ + * Mise a jour: $Date: 2005/10/20 20:58:04 $ * par : $Author: bpoussin $ */ @@ -41,6 +41,10 @@ public class MatrixEncoderDecoderTest extends TestCase { // MatrixEncoderDecoderTest + public MatrixFactory getFactory() throws Exception { + return MatrixFactory.getInstance(); + } + protected void subtestEncoderDecoder(MatrixND mat) throws Exception { // encodage en XML String xml = MatrixHelper.encodeToXML(mat); @@ -61,15 +65,15 @@ MatrixND mat = null; - mat = new MatrixNDImpl("Ma mat", new int[]{3,3,3}); + mat = getFactory().create("Ma mat", new int[]{3,3,3}); subtestEncoderDecoder(mat); - mat = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}); + mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}); subtestEncoderDecoder(mat); // on modifie S1 pour avoir un null au milieu s1.set(1, null); - mat = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); mat.setSemantics(1, Collections.nCopies(3, null)); subtestEncoderDecoder(mat); } Index: lutinmatrix/src/test/org/codelutin/math/matrix/MatrixHelperTest.java diff -u lutinmatrix/src/test/org/codelutin/math/matrix/MatrixHelperTest.java:1.3 lutinmatrix/src/test/org/codelutin/math/matrix/MatrixHelperTest.java:1.4 --- lutinmatrix/src/test/org/codelutin/math/matrix/MatrixHelperTest.java:1.3 Wed Oct 5 20:25:05 2005 +++ lutinmatrix/src/test/org/codelutin/math/matrix/MatrixHelperTest.java Thu Oct 20 20:58:04 2005 @@ -23,9 +23,9 @@ * Created: 29 oct. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Mise a jour: $Date: 2005/10/05 20:25:05 $ + * Mise a jour: $Date: 2005/10/20 20:58:04 $ * par : $Author: bpoussin $ */ @@ -37,6 +37,10 @@ public class MatrixHelperTest extends TestCase { // MatrixHelperTest + public MatrixFactory getFactory() throws Exception { + return MatrixFactory.getInstance(); + } + public void testCoordinatesToString() throws Exception { assertEquals("1", MatrixHelper.coordinatesToString(new int[]{1})); assertEquals("2,3,4,5", MatrixHelper.coordinatesToString(new int[]{2,3,4,5})); @@ -62,14 +66,14 @@ } public void testFill() throws Exception { - MatrixND mat = new MatrixNDImpl(new int[]{3, 3}); + MatrixND mat = getFactory().create(new int[]{3, 3}); MatrixHelper.fill(mat, 4); assertEquals(4, mat.getValue(1,1), 0); } public void testMatrixId() throws Exception { - MatrixND mat = MatrixHelper.matrixId(4); + MatrixND mat = getFactory().matrixId(4); assertTrue(MatrixHelper.sameDimension(new int[]{4,4}, mat.getDim())); assertEquals(0, mat.getValue(1,2), 0); assertEquals(1, mat.getValue(0,0), 0); @@ -79,7 +83,7 @@ } public void testMaxOccurence() throws Exception { - float [] val = new float[5]; + double [] val = new double[5]; assertEquals(0, MatrixHelper.maxOccurence(val), 0); @@ -94,7 +98,7 @@ val[3] = 3; assertEquals(-1, MatrixHelper.maxOccurence(val), 0); - val = new float[6]; + val = new double[6]; assertEquals(0, MatrixHelper.maxOccurence(val), 0); @@ -112,7 +116,7 @@ assertEquals(-3, MatrixHelper.maxOccurence(val), 0); - val = new float[0]; + val = new double[0]; try{ MatrixHelper.maxOccurence(val); assertFalse(true); // on ne passe pas ici Index: lutinmatrix/src/test/org/codelutin/math/matrix/MatrixNDTest.java diff -u lutinmatrix/src/test/org/codelutin/math/matrix/MatrixNDTest.java:1.3 lutinmatrix/src/test/org/codelutin/math/matrix/MatrixNDTest.java:1.4 --- lutinmatrix/src/test/org/codelutin/math/matrix/MatrixNDTest.java:1.3 Mon Nov 8 13:49:55 2004 +++ lutinmatrix/src/test/org/codelutin/math/matrix/MatrixNDTest.java Thu Oct 20 20:58:04 2005 @@ -21,9 +21,9 @@ * * Created: 10 mai 2004 * -* @version $Revision: 1.3 $ +* @version $Revision: 1.4 $ * -* Mise a jour: $Date: 2004/11/08 13:49:55 $ +* Mise a jour: $Date: 2005/10/20 20:58:04 $ * par : $Author: bpoussin $ */ @@ -35,18 +35,22 @@ public class MatrixNDTest extends TestCase { + public MatrixFactory getFactory() throws Exception { + return MatrixFactory.getInstance(); + } + public void testNew() throws Exception { List s1 = Arrays.asList(new String[]{"a", "b", "c"}); List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixNDImpl mat = null; + MatrixND mat = null; - mat = new MatrixNDImpl("Ma mat", new int[]{3,3,3}); + mat = getFactory().create("Ma mat", new int[]{3,3,3}); - mat = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}); + mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}); - mat = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); } @@ -55,13 +59,13 @@ List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixNDImpl mat = null; + MatrixND mat = null; - mat = new MatrixNDImpl(new int[]{3,3,3}); + mat = getFactory().create(new int[]{3,3,3}); assertTrue(null == mat.getSemantics(1).get(1)); - mat = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}); + mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}); // la matrice doit avoir ca propre copie des semantiques s2.set(1, "pas bon"); @@ -76,9 +80,9 @@ List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixNDImpl mat = null; + MatrixND mat = null; - mat = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); assertEquals("Ma mat", mat.getName()); mat.setName("Renamed"); @@ -94,9 +98,9 @@ List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixNDImpl mat = null; + MatrixND mat = null; - mat = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); mat.setValue(1,1,1, 34); assertEquals(34, mat.getValue("b", "f", "l"), 0); @@ -170,9 +174,9 @@ List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixNDImpl mat = null; + MatrixND mat = null; - mat = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); int cpt = 0; for(MatrixIterator i=mat.iterator(); i.hasNext();){ @@ -189,8 +193,8 @@ List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixND mat1 = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); - MatrixND mat2 = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat1 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat2 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); MatrixHelper.fill(mat1, 3); MatrixHelper.fill(mat2, 26); @@ -207,8 +211,8 @@ List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixND mat1 = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); - MatrixND mat2 = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat1 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat2 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); MatrixHelper.fill(mat1, 3); MatrixHelper.fill(mat2, 26); @@ -225,9 +229,9 @@ List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixND mat1 = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); - MatrixND mat2 = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); - MatrixND mat3 = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat1 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat2 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat3 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); MatrixHelper.fill(mat1, 3); MatrixHelper.fill(mat2, 26); @@ -246,7 +250,7 @@ MatrixND mat = null; - mat = new MatrixNDImpl(new int[]{4,4}); + mat = getFactory().create(new int[]{4,4}); MatrixND mat2 = mat; int i=0; for(MatrixIterator mi=mat.iterator(); mi.next();){ @@ -284,7 +288,7 @@ assertEquals(58, mat2.getValue(3, 0), 0); - mat = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); MatrixHelper.fill(mat, 3); mat.setValue(0, 0, 0, 2); @@ -298,7 +302,7 @@ - mat = new MatrixNDImpl(new int[]{6,6,6}); + mat = getFactory().create(new int[]{6,6,6}); MatrixHelper.fill(mat, 3); mat.setValue(0, 0, 0, 0); @@ -319,7 +323,7 @@ public void testTranspose() throws Exception { MatrixND mat = null; - mat = new MatrixNDImpl(new int[]{2,4}); + mat = getFactory().create(new int[]{2,4}); mat.setValue(1, 3, 56); mat.setValue(0, 2, 34); mat.setValue(0, 1, 64); @@ -331,7 +335,7 @@ assertEquals(64, mat.getValue(1, 0), 0); assertEquals(46, mat.getValue(0, 1), 0); - mat = new MatrixNDImpl(new int[]{4}); + mat = getFactory().create(new int[]{4}); mat.setValue(1, 56); mat.setValue(2, 34); mat.setValue(3, 64); @@ -349,8 +353,8 @@ List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixND mat1 = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); - MatrixND mat2 = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat1 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat2 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); MatrixHelper.fill(mat1, 3); MatrixHelper.fill(mat2, 26); @@ -368,8 +372,8 @@ List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixND mat1 = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); - MatrixND mat2 = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat1 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat2 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); MatrixHelper.fill(mat1, 3); MatrixHelper.fill(mat2, 26); @@ -384,8 +388,8 @@ public void testPaste() throws Exception { - MatrixND mat1 = new MatrixNDImpl(new int[]{6, 7, 8}); - MatrixND mat2 = new MatrixNDImpl(new int[]{2, 2, 2}); + MatrixND mat1 = getFactory().create(new int[]{6, 7, 8}); + MatrixND mat2 = getFactory().create(new int[]{2, 2, 2}); MatrixHelper.fill(mat1, 3); MatrixHelper.fill(mat2, 26); @@ -402,7 +406,7 @@ MatrixND mat = null; - mat = new MatrixNDImpl(new int[]{6, 7, 8}); + mat = getFactory().create(new int[]{6, 7, 8}); MatrixHelper.fill(mat, 3); mat = mat.sumOverDim(1); @@ -415,7 +419,7 @@ assertEquals(21, mat.getValue(5, 7), 0); - mat = new MatrixNDImpl(new int[]{2, 2, 2}); + mat = getFactory().create(new int[]{2, 2, 2}); MatrixHelper.fill(mat, 26); mat = mat.sumOverDim(1); @@ -428,7 +432,7 @@ assertEquals(104, mat.getValue(1), 0); - mat = new MatrixNDImpl(new int[]{2, 2, 2}); + mat = getFactory().create(new int[]{2, 2, 2}); MatrixHelper.fill(mat, 6); mat = mat.sumOverDim(1); @@ -442,7 +446,7 @@ - mat = new MatrixNDImpl(new int[]{6, 7, 8}); + mat = getFactory().create(new int[]{6, 7, 8}); MatrixHelper.fill(mat, 3); mat = mat.sumOverDim(1); @@ -455,7 +459,7 @@ assertEquals(21, mat.getValue(5, 7), 0); - mat = new MatrixNDImpl(new int[]{2, 2, 2}); + mat = getFactory().create(new int[]{2, 2, 2}); MatrixHelper.fill(mat, 26); mat = mat.sumOverDim(1); @@ -469,7 +473,7 @@ assertEquals(104, mat.getValue(0, 1), 0); - mat = new MatrixNDImpl(new int[]{2, 2, 2}); + mat = getFactory().create(new int[]{2, 2, 2}); MatrixHelper.fill(mat, 6); mat = mat.sumOverDim(1); Index: lutinmatrix/src/test/org/codelutin/math/matrix/SubMatrixTest.java diff -u lutinmatrix/src/test/org/codelutin/math/matrix/SubMatrixTest.java:1.4 lutinmatrix/src/test/org/codelutin/math/matrix/SubMatrixTest.java:1.5 --- lutinmatrix/src/test/org/codelutin/math/matrix/SubMatrixTest.java:1.4 Tue Nov 9 13:10:50 2004 +++ lutinmatrix/src/test/org/codelutin/math/matrix/SubMatrixTest.java Thu Oct 20 20:58:04 2005 @@ -23,9 +23,9 @@ * Created: 29 oct. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * - * Mise a jour: $Date: 2004/11/09 13:10:50 $ + * Mise a jour: $Date: 2005/10/20 20:58:04 $ * par : $Author: bpoussin $ */ @@ -38,14 +38,18 @@ public class SubMatrixTest extends TestCase { // SubMatrixTest + public MatrixFactory getFactory() throws Exception { + return MatrixFactory.getInstance(); + } + public void testNew() throws Exception { List s1 = Arrays.asList(new String[]{"a", "b", "c"}); List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixNDImpl mat = null; + MatrixND mat = null; - mat = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); MatrixND smat = mat.getSubMatrix(1, 0, 2); assertTrue(Arrays.equals(new int[]{3,2,3}, smat.getDim())); @@ -98,9 +102,9 @@ List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixNDImpl mat = null; + MatrixND mat = null; - mat = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); MatrixND smat = mat.getSubMatrix(1, 0, 2); @@ -143,9 +147,9 @@ List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixNDImpl mat = null; + MatrixND mat = null; - mat = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); MatrixND smat1 = mat.getSubMatrix(1, 0, 2); MatrixND smat2 = smat1.getSubMatrix(0, 2, 1); @@ -172,9 +176,9 @@ List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixNDImpl mat = null; + MatrixND mat = null; - mat = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); MatrixND smat1 = mat.getSubMatrix(1, 0, 2); MatrixND smat2 = smat1.getSubMatrix(0, 2, 1); @@ -190,9 +194,9 @@ List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixNDImpl mat = null; + MatrixND mat = null; - mat = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + mat = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); MatrixND smat1 = mat.getSubMatrix(1, new int []{0, 1}); assertEquals(2, smat1.getDim(1)); @@ -222,9 +226,9 @@ List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixND mat1 = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat1 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); - MatrixND mat2 = new MatrixNDImpl("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); + MatrixND mat2 = getFactory().create("Ma mat", new List[]{s1, s2, s3}, new String[]{"dim abc", "dim efg", "dim klm"}); MatrixHelper.fill(mat1, 5); MatrixHelper.fill(mat2, 3); @@ -271,13 +275,13 @@ List s2 = Arrays.asList(new String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l", "m"}); - MatrixNDImpl mat = null; + MatrixND mat = null; - mat = new MatrixNDImpl("Ma mat", new int[]{4, 4}); + mat = getFactory().create("Ma mat", new int[]{4, 4}); MatrixHelper.fill(mat, 4); - mat = new MatrixNDImpl(mat); + mat = getFactory().create(mat); MatrixND smat1 = mat.getSubMatrix(1, 0, 2); MatrixND smat2 = smat1.getSubMatrix(0, 2, 1);