Index: lutinmatrix/src/test/org/codelutin/math/matrix/ImportExportMatrixTest.java diff -u lutinmatrix/src/test/org/codelutin/math/matrix/ImportExportMatrixTest.java:1.1 lutinmatrix/src/test/org/codelutin/math/matrix/ImportExportMatrixTest.java:1.2 --- lutinmatrix/src/test/org/codelutin/math/matrix/ImportExportMatrixTest.java:1.1 Thu Jun 1 17:38:56 2006 +++ lutinmatrix/src/test/org/codelutin/math/matrix/ImportExportMatrixTest.java Mon Aug 28 11:41:20 2006 @@ -39,7 +39,7 @@ private MatrixND mat2DSemantics; public MatrixFactory getFactory() throws Exception { - return MatrixFactory.getInstance(); + return MatrixFactory.getInstance(DoubleVector.class); } @Override @@ -49,7 +49,7 @@ mat1D.setValue(new int[]{1}, 1); mat1D.setValue(new int[]{2}, 2); mat1D.setValue(new int[]{3}, 3); - mat1D.setValue(new int[]{4}, 4); + mat1D.setValue(new int[]{4}, -4.0E-7); mat2D = new MatrixNDImpl(getFactory(), new int[]{20,10}); mat2D.setValue(new int[]{0, 0}, 0); @@ -61,7 +61,7 @@ mat2D.setValue(new int[]{0, 6}, 4); mat2D.setValue(new int[]{0, 7}, 4); mat2D.setValue(new int[]{1, 8}, 4); - mat2D.setValue(new int[]{2, 9}, 4); + mat2D.setValue(new int[]{2, 9}, -4.0E-7); List sem1 = Arrays.asList(new String[] { "toto", "titi", "tutu", "trtr" }); List sem2 = Arrays.asList(new String[] { "tata", "tete", "tyty" }); @@ -70,18 +70,20 @@ } public void testImport() throws IOException { - String test = "0.0,1.0,2.0,3.0,4.0,4.0,4.0,4.0,0.3,0.0\n" + - "0.0,0.0,7.0,0.0,0.0,2.0,0.0,0.0,4.0,0.0\n" + - "0.0,0.0,8.0,1.0,0.0,0.0,0.0,0.0,0.0,4.0\n"; + String test = "5.0E-7;1.0;2.0;3.0;4.0;4.0;4.0;4.0;0.3;0.0\n" + + "0.0;0.0;7.0;0.0;0.0;2.0;0.0;0.0;4.0;0.0\n" + + "0.0;0.0;8.0;1.0;0.0;0.0;0.0;0.0;0.0;4.0\n"; StringReader reader = new StringReader(test); mat2D.importCSV(reader, new int[]{0,0}); + assertEquals(mat2D.getValue(0,0), 5.0E-7); assertEquals(mat2D.getValue(1,2), 7.0); assertEquals(mat2D.getValue(2,2), 8.0); assertEquals(mat2D.getValue(1,8), 4.0); reader = new StringReader(test); mat2D.importCSV(reader, new int[]{1,1}); + assertEquals(mat2D.getValue(1,1), 5.0E-7); assertEquals(mat2D.getValue(2,3), 7.0); assertEquals(mat2D.getValue(3,3), 8.0); assertEquals(mat2D.getValue(2,9), 4.0); @@ -112,8 +114,8 @@ } public void testSupport() throws Exception { - assertEquals(new MatrixNDImpl(getFactory(), new int[]{1}).isSupportedCSV(), true); - assertEquals(new MatrixNDImpl(getFactory(), new int[]{2,2}).isSupportedCSV(), true); - assertEquals(new MatrixNDImpl(getFactory(), new int[]{3,3,3}).isSupportedCSV(), false); + assertEquals(true, new MatrixNDImpl(getFactory(), new int[]{1}).isSupportedCSV()); + assertEquals(true, new MatrixNDImpl(getFactory(), new int[]{2,2}).isSupportedCSV()); + assertEquals(false, new MatrixNDImpl(getFactory(), new int[]{3,3,3}).isSupportedCSV()); } } Index: lutinmatrix/src/test/org/codelutin/math/matrix/MatrixHelperTest.java diff -u lutinmatrix/src/test/org/codelutin/math/matrix/MatrixHelperTest.java:1.5 lutinmatrix/src/test/org/codelutin/math/matrix/MatrixHelperTest.java:1.6 --- lutinmatrix/src/test/org/codelutin/math/matrix/MatrixHelperTest.java:1.5 Mon Jan 23 13:50:06 2006 +++ lutinmatrix/src/test/org/codelutin/math/matrix/MatrixHelperTest.java Mon Aug 28 11:41:20 2006 @@ -23,14 +23,16 @@ * Created: 29 oct. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * - * Mise a jour: $Date: 2006/01/23 13:50:06 $ + * Mise a jour: $Date: 2006/08/28 11:41:20 $ * par : $Author: bpoussin $ */ package org.codelutin.math.matrix; +import java.util.List; + import junit.framework.TestCase; public class MatrixHelperTest extends TestCase { // MatrixHelperTest @@ -80,6 +82,23 @@ assertEquals(1, mat.getValue(3,3), 0); } + public void testToList() throws Exception { + MatrixND mat1 = getFactory().create(new int[]{3, 2, 1}); + mat1.setValue(0, 0, 0, -1.0E-7); + mat1.setValue(1, 1, 0, 2); + mat1.setValue(2, 1, 0, 5.0E-7); + + List l = mat1.toList(); + String s = String.valueOf(l); + List l2 = MatrixHelper.convertStringToList(s); + + System.out.println(l); + System.out.println(l2); + + assertEquals(l, l2); + + } + public void testMaxOccurence() throws Exception { double [] val = new double[5]; Index: lutinmatrix/src/test/org/codelutin/math/matrix/MatrixNDTest.java diff -u lutinmatrix/src/test/org/codelutin/math/matrix/MatrixNDTest.java:1.7 lutinmatrix/src/test/org/codelutin/math/matrix/MatrixNDTest.java:1.8 --- lutinmatrix/src/test/org/codelutin/math/matrix/MatrixNDTest.java:1.7 Mon Jan 23 13:50:06 2006 +++ lutinmatrix/src/test/org/codelutin/math/matrix/MatrixNDTest.java Mon Aug 28 11:41:20 2006 @@ -21,14 +21,15 @@ * * Created: 10 mai 2004 * -* @version $Revision: 1.7 $ +* @version $Revision: 1.8 $ * -* Mise a jour: $Date: 2006/01/23 13:50:06 $ +* Mise a jour: $Date: 2006/08/28 11:41:20 $ * par : $Author: bpoussin $ */ package org.codelutin.math.matrix; +import java.io.IOException; import java.io.StreamTokenizer; import java.io.StringReader; import java.util.ArrayList; @@ -36,12 +37,15 @@ import java.util.List; import java.util.Stack; +import org.apache.commons.lang.time.DurationFormatUtils; +import org.codelutin.util.StringUtil; + import junit.framework.TestCase; public class MatrixNDTest extends TestCase { public MatrixFactory getFactory() throws Exception { - return MatrixFactory.getInstance(); + return MatrixFactory.getInstance(DoubleVector.class); } public void testNew() throws Exception { @@ -503,9 +507,9 @@ public void testToList() throws Exception { MatrixND mat1 = getFactory().create(new int[]{3, 2, 1}); - mat1.setValue(0, 0, 0, 1); + mat1.setValue(0, 0, 0, 1.0E-7); mat1.setValue(1, 1, 0, 2); - mat1.setValue(2, 1, 0, 3); + mat1.setValue(2, 1, 0, 5.0E-7); List l = mat1.toList(); System.out.println(l); @@ -518,36 +522,141 @@ assertEquals(mat1, mat2); String s = String.valueOf(l); - List l2 = convertStringToList(s); + List l2 = convertStringToList2(s); + List l1 = convertStringToList1(s); + List l0 = convertStringToList0(s); System.out.println(l); System.out.println(l2); + System.out.println(l1); + System.out.println(l0); // implatation fausse assertEquals(l, l2); + + int MAX = 10000; + int dummy = 0; + { + long timeStart = System.nanoTime(); + for (int i=0; i stack = new Stack(); - double value = 0; - StreamTokenizer tok = new StreamTokenizer(new StringReader(s)); - int v = tok.nextToken(); - while (v != StreamTokenizer.TT_EOF) { - if (v == '[') { - stack.push(new ArrayList()); - } else if (v == ']'){ - List current = stack.pop(); - if (stack.empty()) { - result = current; - } else { - stack.peek().add(current); - } - } else if (v == StreamTokenizer.TT_NUMBER) { - value = tok.nval; + StringBuffer number = new StringBuffer(20); // initial to 20 char + + for (int i=0; i stack = new Stack(); + StringBuffer number = new StringBuffer(20); // initial to 20 char + + StreamTokenizer tok = new StreamTokenizer(new StringReader(s)); + int v = tok.nextToken(); + while (v != StreamTokenizer.TT_EOF) { + if (v == '[') { + stack.push(new ArrayList()); + } else if (v == ']'){ + List current = stack.pop(); + if (stack.empty()) { + result = current; + } else { + stack.peek().add(current); + } + } else if (v == StreamTokenizer.TT_NUMBER) { + double value = tok.nval; + stack.peek().add(value); + } + v = tok.nextToken(); + } return result; }