Index: lutinmatrix/src/test/org/codelutin/math/matrix/BasicMatrixTest.java diff -u lutinmatrix/src/test/org/codelutin/math/matrix/BasicMatrixTest.java:1.2 lutinmatrix/src/test/org/codelutin/math/matrix/BasicMatrixTest.java:1.3 --- lutinmatrix/src/test/org/codelutin/math/matrix/BasicMatrixTest.java:1.2 Thu Nov 4 13:50:17 2004 +++ lutinmatrix/src/test/org/codelutin/math/matrix/BasicMatrixTest.java Mon Nov 8 13:49:55 2004 @@ -23,9 +23,9 @@ * Created: 27 oct. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Mise a jour: $Date: 2004/11/04 13:50:17 $ + * Mise a jour: $Date: 2004/11/08 13:49:55 $ * par : $Author: bpoussin $ */ @@ -47,10 +47,15 @@ assertTrue(true); // mais on doit etre la } + try{ + mat = new BasicMatrix(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[]{0}); mat = new BasicMatrix(new int[]{100}); - mat = new BasicMatrix(new int[]{10,0}); + mat = new BasicMatrix(new int[]{10,1}); mat = new BasicMatrix(new int[]{10,10,10,10}); try{ mat = new BasicMatrix(new int[]{-10}); Index: lutinmatrix/src/test/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java diff -u lutinmatrix/src/test/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java:1.2 lutinmatrix/src/test/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java:1.3 --- lutinmatrix/src/test/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java:1.2 Thu Nov 4 13:50:17 2004 +++ lutinmatrix/src/test/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java Mon Nov 8 13:49:55 2004 @@ -23,9 +23,9 @@ * Created: 31 oct. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Mise a jour: $Date: 2004/11/04 13:50:17 $ + * Mise a jour: $Date: 2004/11/08 13:49:55 $ * par : $Author: bpoussin $ */ @@ -37,29 +37,21 @@ import java.util.Collections; import java.util.List; import junit.framework.TestCase; +import org.codelutin.xml.XMLEncoderDecoder; public class MatrixEncoderDecoderTest extends TestCase { // MatrixEncoderDecoderTest protected void subtestEncoderDecoder(MatrixND mat) throws Exception { - MatrixND mat2 = null; - StringWriter out = null; - StringWriter out2 = null; - MatrixEncoder encoder = null; - MatrixDecoder decoder = null; - // encodage en XML - encoder = new MatrixEncoder(out = new StringWriter()); - encoder.writeMatrice(mat); + String xml = MatrixHelper.encodeToXML(mat); // decodage depuis le XML - decoder = new MatrixDecoder(new StringReader(out.toString())); - mat2 = decoder.readMatrix(); + MatrixND mat2 = MatrixHelper.decodeFromXML(xml); // reencodage de la matrice resultat - encoder = new MatrixEncoder(out2 = new StringWriter()); - encoder.writeMatrice(mat2); + String xml2 = MatrixHelper.encodeToXML(mat2); // on verifie que les 2 matrices sont egals et leur representation // XML aussi assertEquals(mat, mat2); - assertEquals(out.toString(), out2.toString()); + assertEquals(xml, xml2); } public void testEncoderDecoder() throws Exception { Index: lutinmatrix/src/test/org/codelutin/math/matrix/MatrixNDTest.java diff -u lutinmatrix/src/test/org/codelutin/math/matrix/MatrixNDTest.java:1.2 lutinmatrix/src/test/org/codelutin/math/matrix/MatrixNDTest.java:1.3 --- lutinmatrix/src/test/org/codelutin/math/matrix/MatrixNDTest.java:1.2 Thu Nov 4 13:50:17 2004 +++ lutinmatrix/src/test/org/codelutin/math/matrix/MatrixNDTest.java Mon Nov 8 13:49:55 2004 @@ -21,9 +21,9 @@ * * Created: 10 mai 2004 * -* @version $Revision: 1.2 $ +* @version $Revision: 1.3 $ * -* Mise a jour: $Date: 2004/11/04 13:50:17 $ +* Mise a jour: $Date: 2004/11/08 13:49:55 $ * par : $Author: bpoussin $ */ @@ -439,6 +439,51 @@ assertEquals(1, mat.getNbDim()); assertEquals(1, mat.getDim(0)); assertEquals(48, mat.getValue(0), 0); + + + + mat = new MatrixNDImpl(new int[]{6, 7, 8}); + MatrixHelper.fill(mat, 3); + + mat = mat.sumOverDim(1); + assertEquals(21, mat.getValue(0, 0, 0), 0); + mat = mat.reduce(2); + assertEquals(2, mat.getNbDim()); + assertEquals(6, mat.getDim(0)); + assertEquals(8, mat.getDim(1)); + assertEquals(21, mat.getValue(0, 0), 0); + assertEquals(21, mat.getValue(5, 7), 0); + + + mat = new MatrixNDImpl(new int[]{2, 2, 2}); + MatrixHelper.fill(mat, 26); + + mat = mat.sumOverDim(1); + mat = mat.sumOverDim(0); + assertEquals(104, mat.getValue(0, 0, 0), 0); + mat = mat.reduce(2); + assertEquals(2, mat.getNbDim()); + assertEquals(1, mat.getDim(0)); + assertEquals(2, mat.getDim(1)); + assertEquals(104, mat.getValue(0, 0), 0); + assertEquals(104, mat.getValue(0, 1), 0); + + + mat = new MatrixNDImpl(new int[]{2, 2, 2}); + MatrixHelper.fill(mat, 6); + + mat = mat.sumOverDim(1); + mat = mat.sumOverDim(2); + mat = mat.sumOverDim(0); + assertEquals(48, mat.getValue(0, 0, 0), 0); + mat = mat.reduce(5); + assertEquals(3, mat.getNbDim()); + assertEquals(1, mat.getDim(0)); + assertEquals(1, mat.getDim(1)); + assertEquals(1, mat.getDim(2)); + assertEquals(48, mat.getValue(0, 0, 0), 0); + + } } Index: lutinmatrix/src/test/org/codelutin/math/matrix/SubMatrixTest.java diff -u lutinmatrix/src/test/org/codelutin/math/matrix/SubMatrixTest.java:1.2 lutinmatrix/src/test/org/codelutin/math/matrix/SubMatrixTest.java:1.3 --- lutinmatrix/src/test/org/codelutin/math/matrix/SubMatrixTest.java:1.2 Thu Nov 4 13:50:17 2004 +++ lutinmatrix/src/test/org/codelutin/math/matrix/SubMatrixTest.java Mon Nov 8 13:49:55 2004 @@ -23,9 +23,9 @@ * Created: 29 oct. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Mise a jour: $Date: 2004/11/04 13:50:17 $ + * Mise a jour: $Date: 2004/11/08 13:49:55 $ * par : $Author: bpoussin $ */ @@ -183,6 +183,38 @@ assertEquals(34, smat2.getValue("c", "e", "k"), 0); smat2.setValue("c", "f", "l", 23); assertEquals(23, smat2.getValue(0, 1, 1), 0); + } + + public void testSubMapping() 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; + + mat = new MatrixNDImpl("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)); + assertEquals(Arrays.asList(new String[]{"e","f"}), smat1.getSemantics(1)); + MatrixND smat2 = smat1.getSubMatrix(0, new Object[]{"c"}); + assertEquals(1, smat2.getDim(0)); + assertEquals(Arrays.asList(new String[]{"c"}), smat2.getSemantics(0)); + + mat.setValue("c", "f", "k", 12); + assertEquals(12, smat1.getValue(2, 1, 0), 0); + assertEquals(12, smat1.getValue("c", "f", "k"), 0); + assertEquals(12, smat2.getValue(0, 1, 0), 0); + assertEquals(12, smat2.getValue("c", "f", "k"), 0); + + smat2.setValue(0, 0, 0, 34); + assertEquals(34, smat2.getValue("c", "e", "k"), 0); + assertEquals(34, mat.getValue(2, 0, 0), 0); + assertEquals(34, mat.getValue("c", "e", "k"), 0); + smat2.setValue("c", "f", "l", 23); + assertEquals(23, smat2.getValue(0, 1, 1), 0); + assertEquals(23, mat.getValue(2, 1, 1), 0); + assertEquals(23, mat.getValue("c", "f", "l"), 0); } public void testSubAdd() throws Exception {