Author: chatellier Date: 2009-03-03 10:19:18 +0000 (Tue, 03 Mar 2009) New Revision: 120 Added: lutinmatrix/trunk/src/test/resources/ lutinmatrix/trunk/src/test/resources/log4j.properties Removed: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java Modified: lutinmatrix/trunk/changelog.txt lutinmatrix/trunk/pom.xml lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrix.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrixIterator.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DimensionHelper.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleBigVector.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleVector.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatBigVector.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatVector.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MapFunction.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixEncoder.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixException.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIterator.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIteratorImpl.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SemanticList.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/Vector.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelListener.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModel.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelLinear.java lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelND.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixBigTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/FloatVectorTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/ImportExportMatrixTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/PerfTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/SubMatrixTest.java lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/gui/MatrixTableModelTest.java Log: Clean code, move test to junit4. Remove converter form lutinxml. Modified: lutinmatrix/trunk/changelog.txt =================================================================== --- lutinmatrix/trunk/changelog.txt 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/changelog.txt 2009-03-03 10:19:18 UTC (rev 120) @@ -1,3 +1,8 @@ +ver-1.3 chatellier 2009xxxx + * Move test to junit 4 + * Update copyright + * Ajout de la serialisation des matrices + ver-1.2 chemit 20090218 * Switch to lutinutil 1.0 * Use lutinproject:3.4 Modified: lutinmatrix/trunk/pom.xml =================================================================== --- lutinmatrix/trunk/pom.xml 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/pom.xml 2009-03-03 10:19:18 UTC (rev 120) @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> <!-- ************************************************************* --> Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,18 +15,6 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * AbstractMatrixND.java - * - * Created: 29 oct. 2004 - * - * @author Benjamin Poussin <poussin@codelutin.com> - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - package org.codelutin.math.matrix; import java.io.IOException; @@ -45,26 +33,53 @@ import org.apache.commons.logging.LogFactory; import org.codelutin.util.ArrayUtil; +/** + * AbstractMatrixND. + * + * Created: 29 oct. 2004 + * + * @author Benjamin Poussin <poussin@codelutin.com> + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ public abstract class AbstractMatrixND implements MatrixND { // AbstractMatrixND + /** serialVersionUID. */ + private static final long serialVersionUID = -6838751468730930727L; + /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(AbstractMatrixND.class); + private static Log log = LogFactory.getLog(AbstractMatrixND.class); - abstract public MatrixIterator iterator(); + public abstract MatrixIterator iterator(); - abstract public double getValue(int[] coordinates); + public abstract double getValue(int[] coordinates); - abstract public void setValue(int[] coordinates, double d); + public abstract void setValue(int[] coordinates, double d); - transient protected DimensionHelper dimHelper = new DimensionHelper(); + protected transient DimensionHelper dimHelper = new DimensionHelper(); - transient protected MatrixFactory factory = null; + protected transient MatrixFactory factory = null; + protected String name = ""; + protected String[] dimNames = null; + protected int[] dim = null; + protected List[] semantics = null; + protected double defaultValue = 0; + /** + * Separateur CSV par défaut le point virgule. + */ + public static char CSV_SEPARATOR = ';'; + + protected static final Pattern NUMBER = Pattern + .compile(" *[+-]?[0-9]*\\.?[0-9]+([eE][+-]?[0-9]+)? *"); + protected void init(int[] dim) { this.dim = new int[dim.length]; System.arraycopy(dim, 0, this.dim, 0, dim.length); @@ -279,7 +294,7 @@ public double getValue(int x, int y, int z, int t) { return getValue(dimHelper.get(x, y, z, t)); - }; + } public void setValue(Object[] coordinates, double d) { setValue( @@ -845,11 +860,6 @@ } /** - * Separateur CSV par défaut la virgule - */ - public static char CSV_SEPARATOR = ';'; - - /** * Determine si la matrice supporte l'import et l'export CSV * * @return support du CSV @@ -858,9 +868,6 @@ return getNbDim() <= 2; } - Pattern NUMBER = Pattern - .compile(" *[+-]?[0-9]*\\.?[0-9]+([eE][+-]?[0-9]+)? *"); - /** * Import depuis un reader au format CSV des données dans la matrice * Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrix.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrix.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrix.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,18 +15,6 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * BasicMatrix.java - * - * Created: 27 oct. 2004 - * - * @author Benjamin Poussin <poussin@codelutin.com> - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - package org.codelutin.math.matrix; import java.util.Arrays; @@ -37,6 +25,14 @@ /** * Objet matrice qui ne permet que le stockage de double dans un matrice à * autant de dimension que l'on souhaite. + * + * Created: 27 oct. 2004 + * + * @author Benjamin Poussin <poussin@codelutin.com> + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ */ public class BasicMatrix { // BasicMatrix @@ -46,6 +42,7 @@ protected int[] dimensions = null; /** La matrice en représentation linéaire */ protected Vector data = null; + /** * tableau de facteur permettant de convertir les coordonnées dans la * matrice en un indice dans la représentation linéaire de la matrice @@ -208,8 +205,8 @@ for (int i = 0; i < dim.length; i++) { if (dim[i] <= 0) { throw new IllegalArgumentException(I18n._( - "lutinmatrix.invalid.size", new Integer(i), - new Integer(dim[i]))); + "lutinmatrix.invalid.size", Integer.valueOf(i), + Integer.valueOf(dim[i]))); } } } Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrixIterator.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrixIterator.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrixIterator.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,8 +15,10 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * BasicMatrixIterator.java +package org.codelutin.math.matrix; + +/** + * BasicMatrixIterator. * * Created: 28 oct. 2004 * @@ -26,35 +28,32 @@ * Mise a jour: $Date$ * par : $Author$ */ - -package org.codelutin.math.matrix; - public interface BasicMatrixIterator { // BasicMatrixIterator /** - * Retourne vrai s'il existe un suivant + * Retourne vrai s'il existe un suivant. * * @return vrai s'il y a un suivant, faux sinon */ public boolean hasNext(); /** - * Passe à l'élément suivant + * Passe à l'élément suivant. */ public boolean next(); /** - * Retourne les coordonnés de l'élément + * Retourne les coordonnés de l'élément. */ public int[] getCoordinates(); /** - * Retourne la valeur courant pointé par l'iterator + * Retourne la valeur courant pointé par l'iterator. */ public double getValue(); /** - * Modifie la valeur courant pointé par l'iterator + * Modifie la valeur courant pointé par l'iterator. */ public void setValue(double value); Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DimensionHelper.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DimensionHelper.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DimensionHelper.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,18 +15,6 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * DimensionHelper.java - * - * Created: 29 oct. 2004 - * - * @author Benjamin Poussin <poussin@codelutin.com> - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - package org.codelutin.math.matrix; /** @@ -36,6 +24,14 @@ * cette classe, par exemple il ne faut pas l'utiliser dans une méthode qui * appelle une autre methode réutilisant le meme objet, car il sera alors * modifier alors qu'il ne le faut pas pour la premiere methode appelée. + * + * Created: 29 oct. 2004 + * + * @author Benjamin Poussin <poussin@codelutin.com> + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ */ public class DimensionHelper { // DimensionHelper Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleBigVector.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleBigVector.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleBigVector.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,8 +15,12 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * DoubleBigVector.java +package org.codelutin.math.matrix; + +import java.util.Arrays; + +/** + * DoubleBigVector. * * Created: 6 octobre 2005 02:54:36 CEST * @@ -26,11 +30,6 @@ * Last update: $Date$ * by : $Author$ */ - -package org.codelutin.math.matrix; - -import java.util.Arrays; - public class DoubleBigVector implements Vector { // DoubleBigVector protected double data[] = null; Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleVector.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleVector.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleVector.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,18 +15,6 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * FloatVector.java - * - * Created: 6 octobre 2005 01:29:23 CEST - * - * @author Benjamin POUSSIN <poussin@codelutin.com> - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - package org.codelutin.math.matrix; import java.util.Arrays; @@ -34,10 +22,18 @@ import org.apache.commons.collections.primitives.ArrayDoubleList; /** - * Permet de stocker des données à une position lineair et de la redemander + * Permet de stocker des données à une position lineaire et de la redemander. * Cette classe ne gére que les données lineaire. L'avantage de cette classe est * de ne conserver que les elements differents de la valeur par defaut, ce qui * minimize la taille du tableau necessaire a conserver les données. + * + * Created: 6 octobre 2005 01:29:23 CEST + * + * @author Benjamin POUSSIN <poussin@codelutin.com> + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ */ public class DoubleVector implements Vector { // FloatVector Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatBigVector.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatBigVector.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatBigVector.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,8 +15,12 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * FloatBigVector.java +package org.codelutin.math.matrix; + +import java.util.Arrays; + +/** + * FloatBigVector. * * Created: 6 octobre 2005 02:54:36 CEST * @@ -26,11 +30,6 @@ * Last update: $Date$ * by : $Author$ */ - -package org.codelutin.math.matrix; - -import java.util.Arrays; - public class FloatBigVector implements Vector { // FloatBigVector protected float data[] = null; Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatVector.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatVector.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatVector.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,18 +15,6 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * FloatVector.java - * - * Created: 6 octobre 2005 01:29:23 CEST - * - * @author Benjamin POUSSIN <poussin@codelutin.com> - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - package org.codelutin.math.matrix; import java.util.Arrays; @@ -38,6 +26,14 @@ * Cette classe ne gére que les données lineaire. L'avantage de cette classe est * de ne conserver que les elements differents de la valeur par defaut, ce qui * minimize la taille du tableau necessaire a conserver les données. + * + * Created: 6 octobre 2005 01:29:23 CEST + * + * @author Benjamin POUSSIN <poussin@codelutin.com> + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ */ public class FloatVector implements Vector { // FloatVector Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MapFunction.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MapFunction.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MapFunction.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,8 +15,11 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MapFunction.java +package org.codelutin.math.matrix; + +/** + * Permet de faire un traitement sur des valeurs et d'en retourner + * des nouvelles. * * Created: 27 oct. 2004 * @@ -26,9 +29,6 @@ * Mise a jour: $Date$ * par : $Author$ */ - -package org.codelutin.math.matrix; - public interface MapFunction { // MapFunction /** Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixEncoder.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixEncoder.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixEncoder.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,8 +15,16 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatriceEncoder.java +package org.codelutin.math.matrix; + +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * MatriceEncoder. * * Created: 21 oct. 2004 * @@ -26,15 +34,6 @@ * Mise a jour: $Date$ * par : $Author$ */ - -package org.codelutin.math.matrix; - -import java.io.IOException; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - public class MatrixEncoder { // MatriceEncoder protected Writer out = null; Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixException.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixException.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixException.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /*##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,216 +15,201 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatrixFactory.java - * - * Created: 11 octobre 2005 20:15:20 CEST - * - * @author Benjamin POUSSIN <poussin@codelutin.com> - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - package org.codelutin.math.matrix; import java.lang.reflect.Constructor; -import java.lang.reflect.Method; import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - /** * Cette classe permet de creer des matrices, toutes les creations de matrice * doivent etre faite a travers cette classe. Cette classe permet de modifier la * representation interne des matrices de facon simple. * <p> - * + * Created: 11 octobre 2005 20:15:20 CEST + * + * @author Benjamin POUSSIN <poussin@codelutin.com> + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ */ public class MatrixFactory { // MatrixFactory - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(MatrixFactory.class); + /* following code in only an exception generator since + * lutinxml in not used anymore :) + static { - static { - // on essai d'enregistrer le converter XML - try { - // Il faut le faire par pur introspection sinon l'exception - // NoClassDefFoundError est levé avant d'entrer dans le constructeur - // static :( - Class converterClass = Class - .forName("org.codelutin.math.matrix.MatrixNDXMLConverter"); - Object converter = converterClass.newInstance(); + // on essai d'enregistrer le converter XML + try { + // Il faut le faire par pur introspection sinon l'exception + // NoClassDefFoundError est levé avant d'entrer dans le constructeur + // static :( + Class converterClass = Class + .forName("org.codelutin.math.matrix.MatrixNDXMLConverter"); + Object converter = converterClass.newInstance(); - Class converterFactoryClass = Class - .forName("org.codelutin.xml.XMLConverterFactory"); - Method m = converterFactoryClass.getMethod("addConverter", - Class.class, Class - .forName("org.codelutin.xml.XMLConverter")); - m.invoke(null, MatrixND.class, converter); + Class converterFactoryClass = Class + .forName("org.codelutin.xml.XMLConverterFactory"); + Method m = converterFactoryClass.getMethod("addConverter", + Class.class, Class + .forName("org.codelutin.xml.XMLConverter")); + m.invoke(null, MatrixND.class, converter); - // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class, - // new MatrixNDXMLConverter()); - log.info("Converter XML pour MatrixND ajoute"); + // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class, + // new MatrixNDXMLConverter()); + log.info("Converter XML pour MatrixND ajoute"); - // on essai d'enregistrer le converter JDBC - // le JDBC depend du XML - try { - converterClass = Class - .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter"); - converter = converterClass.newInstance(); + // on essai d'enregistrer le converter JDBC + // le JDBC depend du XML + try { + converterClass = Class + .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter"); + converter = converterClass.newInstance(); - converterFactoryClass = Class - .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory"); - m = converterFactoryClass - .getMethod( - "addConverter", - Class.class, - Class - .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer")); - m.invoke(null, MatrixND.class, converter); + converterFactoryClass = Class + .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory"); + m = converterFactoryClass + .getMethod( + "addConverter", + Class.class, + Class.forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer")); + m.invoke(null, MatrixND.class, converter); - // Class converterClass = - // org.codelutin.math.matrix.MatrixNDJDBCConverter(); - // JDBCTransformerFactory - // .addConverter(MatrixND.class, new MatrixNDJDBCConverter()); - log.info("Converter JDBC pour MatrixND ajoute"); - } catch (Throwable eee) { - log - .info("librairie topia non presente. Import/Export JDBC impossible"); - log.debug("L'exception etait", eee); - } + // Class converterClass = + // org.codelutin.math.matrix.MatrixNDJDBCConverter(); + // JDBCTransformerFactory + // .addConverter(MatrixND.class, new MatrixNDJDBCConverter()); + log.info("Converter JDBC pour MatrixND ajoute"); + } catch (Throwable eee) { + log + .info("librairie topia non presente. Import/Export JDBC impossible"); + log.debug("L'exception etait", eee); + } - } catch (Throwable eee) { - log - .info("librairie lutinxml non presente. Import/Export XML impossible"); - log.debug("L'exception etait", eee); - } + } catch (Throwable eee) { + log + .info("librairie lutinxml non presente. Import/Export XML impossible"); + log.debug("L'exception etait", eee); + } - } + }*/ - /** Valeur par defaut si aucun type de Vector n'est donné */ - static protected Class defaultVectorClass = DoubleBigVector.class; + /** Valeur par defaut si aucun type de Vector n'est donné */ + protected static Class defaultVectorClass = DoubleBigVector.class; - protected Class vectorClass = null; + protected Class vectorClass = null; - protected MatrixFactory(Class vectorClass) { - this.vectorClass = vectorClass; - } + protected MatrixFactory(Class vectorClass) { + this.vectorClass = vectorClass; + } - static public void setDefaultVectorClass(Class vectorClass) { - defaultVectorClass = vectorClass; - } + public static void setDefaultVectorClass(Class vectorClass) { + defaultVectorClass = vectorClass; + } - static public Class getDefaultVectorClass() { - return defaultVectorClass; - } + public static Class getDefaultVectorClass() { + return defaultVectorClass; + } - /** - * Retourne une factory utilisant vectorClass comme classe de base a - * l'implantation des matrices - */ - static public MatrixFactory getInstance(Class vectorClass) { - return new MatrixFactory(vectorClass); - } + /** + * Retourne une factory utilisant vectorClass comme classe de base a + * l'implantation des matrices + */ + public static MatrixFactory getInstance(Class vectorClass) { + return new MatrixFactory(vectorClass); + } - /** - * Utilise par defaut {@link FloatBigVector} - */ - static public MatrixFactory getInstance() { - return getInstance(defaultVectorClass); - } + /** + * Utilise par defaut {@link FloatBigVector} + */ + public static MatrixFactory getInstance() { + return getInstance(defaultVectorClass); + } - public MatrixND create(int[] dim) { - return new MatrixNDImpl(this, dim); - } + public MatrixND create(int[] dim) { + return new MatrixNDImpl(this, dim); + } - /** - * - * @param values - * The values to fill the matrix - * @param dim - * An array representing the dimensions of the matrix - * @return a 2D matrix filled with the values, null if the dimension is more - * than 2 - */ + /** + * Convert a double array into matrix. + * + * @param values The values to fill the matrix + * @param dim An array representing the dimensions of the matrix + * @return a 2D matrix filled with the values, null if the dimension is more than 2 + */ + public MatrixND create(double[] values, int[] dim) { - public MatrixND create(double[] values, int[] dim) { + if (dim.length > 2) { + return null; + } + MatrixNDImpl matrix = new MatrixNDImpl(this, dim); - if (dim.length > 2) { - return null; - } - MatrixNDImpl matrix = new MatrixNDImpl(this, dim); + if (dim.length == 2) { + for (int i = 0; i < dim[0]; i++) { + for (int j = 0; j < dim[1]; j++) { + int[] coordinates = { i, j }; + matrix.setValue(coordinates, values[i * dim[0] + j]); + } + } + } + if (dim.length == 1) { + for (int i = 0; i < dim[0]; i++) { + int[] coordinates = { i }; + matrix.setValue(coordinates, values[i]); + } + } - if (dim.length == 2) { - for (int i = 0; i < dim[0]; i++) { - for (int j = 0; j < dim[1]; j++) { - int[] coordinates = {i,j}; - matrix.setValue(coordinates, values[i * dim[0] + j]); - } - } - } - if (dim.length == 1){ - for (int i=0;i<dim[0];i++) { - int[] coordinates = {i}; - matrix.setValue(coordinates, values[i]); - } - } + return matrix; + } - return matrix; - } + public MatrixND create(List[] semantics) { + return new MatrixNDImpl(this, semantics); + } - public MatrixND create(List[] semantics) { - return new MatrixNDImpl(this, semantics); - } + public MatrixND create(String name, int[] dim) { + return new MatrixNDImpl(this, name, dim); + } - public MatrixND create(String name, int[] dim) { - return new MatrixNDImpl(this, name, dim); - } + public MatrixND create(String name, int[] dim, String[] dimNames) { + return new MatrixNDImpl(this, name, dim, dimNames); + } - public MatrixND create(String name, int[] dim, String[] dimNames) { - return new MatrixNDImpl(this, name, dim, dimNames); - } + public MatrixND create(String name, List[] semantics) { + return new MatrixNDImpl(this, name, semantics); + } - public MatrixND create(String name, List[] semantics) { - return new MatrixNDImpl(this, name, semantics); - } + public MatrixND create(String name, List[] semantics, String[] dimNames) { + return new MatrixNDImpl(this, name, semantics, dimNames); + } - public MatrixND create(String name, List[] semantics, String[] dimNames) { - return new MatrixNDImpl(this, name, semantics, dimNames); - } + public MatrixND create(MatrixND matrix) { + return new MatrixNDImpl(this, matrix); + } - public MatrixND create(MatrixND matrix) { - return new MatrixNDImpl(this, matrix); - } + /** + * Crée une nouvelle matrice identité. Une matrice identité est une matrice + * à 2 dimensions dont tous les éléments de la diagonal vaut 1 + * + * @param size la taille de la matrice + * @return une nouvelle matrice identité + */ + public MatrixND matrixId(int size) { + MatrixND result = create(new int[] { size, size }); + for (int i = 0; i < size; i++) { + result.setValue(i, i, 1); + } + return result; + } - /** - * Crée une nouvelle matrice identité. Une matrice identité est une matrice - * à 2 dimensions dont tous les éléments de la diagonal vaut 1 - * - * @param size - * la taille de la matrice - * @return une nouvelle matrice identité - */ - public MatrixND matrixId(int size) { - MatrixND result = create(new int[] { size, size }); - for (int i = 0; i < size; i++) { - result.setValue(i, i, 1); - } - return result; - } + protected Vector createVector(int length) { + try { + Constructor c = vectorClass + .getConstructor(new Class[] { Integer.TYPE }); + return (Vector) c.newInstance(new Object[] { length }); + } catch (Exception eee) { + throw new RuntimeException("Can't create vector", eee); + } + } - protected Vector createVector(int length) { - try { - Constructor c = vectorClass - .getConstructor(new Class[] { Integer.TYPE }); - return (Vector) c.newInstance(new Object[] { length }); - } catch (Exception eee) { - throw new RuntimeException("Can't create vector", eee); - } - } - } // MatrixFactory Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,18 +15,6 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatrixHelper.java - * - * Created: 28 oct. 2004 - * - * @author Benjamin Poussin <poussin@codelutin.com> - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - package org.codelutin.math.matrix; import java.io.StreamTokenizer; @@ -39,23 +27,27 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -public class MatrixHelper { +/** + * MatrixHelper. + * + * Created: 28 oct. 2004 + * + * @author Benjamin Poussin <poussin@codelutin.com> + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class MatrixHelper { // MatrixHelper /** - * Logger for this class - */ - private static final Log log = LogFactory.getLog(MatrixHelper.class); - - // MatrixHelper - - /** * Convert Matrix to identity matrix must have 2 dimensions. If dimension * haven't same length, then the small dimension is used. * * @param mat * @return */ - static public MatrixND convertToId(MatrixND mat) { + public static MatrixND convertToId(MatrixND mat) { int size = mat.getDim(0); if (size > mat.getDim(1)) { size = mat.getDim(1); @@ -72,7 +64,7 @@ /** * Permet de relire une chaine du type [[[1, 2], [3, 4]],[[3, 5], [1, 4]]] * <p> - * Remarque: une premiere implatantion avait ete faite en utilisant + * Remarque: une premiere implantantion avait ete faite en utilisant * {@link StreamTokenizer} mais en fait il y a un bug dedans, il ne sait pas * parser les chiffres avec un exposant: 5.0E-7 par exemple est lu comme 5.0 * :( @@ -84,7 +76,7 @@ * @param s la chaine representant les listes de liste * @return une liste de liste ... de Double */ - static public List convertStringToList(String s) { + public static List convertStringToList(String s) { List result = null; Stack<List> stack = new Stack<List>(); StringBuffer number = new StringBuffer(20); // initial to 20 char @@ -130,12 +122,12 @@ } /** - * permet de donner une repr�sentation String d'un tableau de coordonn�es + * permet de donner une représentation String d'un tableau de coordonnées * - * @param coordinates les coordonn�es - * @return la chaine demand�e de la forme 1,3,34,23 + * @param coordinates les coordonnées + * @return la chaine demandée de la forme 1,3,34,23 */ - static public String coordinatesToString(int[] coordinates) { + public static String coordinatesToString(int[] coordinates) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < coordinates.length; i++) { sb.append(coordinates[i]); @@ -147,47 +139,48 @@ } /** - * permet de donner une repr�sentation String d'un tableau de coordonn�es + * permet de donner une représentation String d'un tableau de coordonnées * - * @param coordinates les coordonn�es - * @return la chaine demand�e de la forme "Ob1","Ob2,"Ob3", ... la chaine - * prise pour l'objet est celle retourn�e par la m�thode toString de + * @param coordinates les coordonnées + * @return la chaine demandée de la forme "Ob1","Ob2,"Ob3", ... la chaine + * prise pour l'objet est celle retournée par la méthode toString de * l'objet */ - static public String coordinatesToString(Object[] coordinates) { + public static String coordinatesToString(Object[] coordinates) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < coordinates.length; i++) { sb.append(coordinates[i]); - if (i + 1 < coordinates.length) + if (i + 1 < coordinates.length) { sb.append(','); + } } return sb.toString(); } /** - * Permet de savoir si deux dimension sont identique + * Permet de savoir si deux dimension sont identiques. */ - static public boolean sameDimension(int[] dim1, int[] dim2) { + public static boolean sameDimension(int[] dim1, int[] dim2) { return Arrays.equals(dim1, dim2); } /** - * Permet de convertir des coordonn�es d�fini par des entiers en coordonn�e + * Permet de convertir des coordonnées définies par des entiers en coordonnées * semantique par des objets * - * @param semantics la semantique � utilis� pour la conversion - * @param coordinates les coordonn�es � convertir - * @return un tableau donnant les coordonn�es sous forme semantique s'il n'y + * @param semantics la semantique à utilisé pour la conversion + * @param coordinates les coordonnées à convertir + * @return un tableau donnant les coordonnées sous forme semantique s'il n'y * a pas de semantique (liste pleine de null) alors un objet Integer - * est cr�er pour repr�senter la semantique de la dimension. + * est créer pour représenter la semantique de la dimension. */ - static public Object[] dimensionToSemantics(List[] semantics, + public static Object[] dimensionToSemantics(List[] semantics, int[] coordinates) { Object[] result = new Object[coordinates.length]; for (int i = 0; i < result.length; i++) { result[i] = semantics[i].get(coordinates[i]); if (result[i] == null) { - result[i] = new Integer(coordinates[i]); + result[i] = Integer.valueOf(coordinates[i]); } } return result; @@ -204,7 +197,7 @@ * Integer alors la valeur de l'integer est utilisé pour la * conversion. */ - static public int[] semanticsToDimension(List[] semantics, + public static int[] semanticsToDimension(List[] semantics, Object[] coordinates) { int[] result = new int[coordinates.length]; for (int i = 0; i < coordinates.length; i++) { @@ -220,12 +213,14 @@ /** * Permet de retrouver la position d'un objet dans une liste * - * @param semantics la semantique � utilis� pour la recherche + * @param semantics la semantique à utilisé pour la recherche * @param dim la dimension dans lequel il faut faire la recherche - * @param o l'objet � rechercher - * @return la position de l'objet dans la dimension demand�e + * @param o l'objet à rechercher + * @return la position de l'objet dans la dimension demandée + * + * @throws NoSuchElementException If element doesn't exists */ - static public int indexOf(List[] semantics, int dim, Object o) + public static int indexOf(List[] semantics, int dim, Object o) throws NoSuchElementException { if (o instanceof Integer) { return ((Integer) o).intValue(); @@ -236,20 +231,20 @@ } if (result == -1) { throw new NoSuchElementException( - "L'objet pass� en argument n'a pas �t� retrouve ou la dimension donn�e ne convient pas:" + "L'objet passé en argument n'a pas été retrouvé ou la dimension donnée ne convient pas:" + o + " in " + semantics[dim]); } return result; } /** - * Permet de remplir toute la matrice avec la m�me donn�e + * Permet de remplir toute la matrice avec la même donnée * - * @param mat la matrice � remplir + * @param mat la matrice à remplir * @param value la valeur de remplissage - * @return la matrice pass� en param�tre + * @return la matrice passé en paramêtre */ - static public MatrixND fill(MatrixND mat, final double value) { + public static MatrixND fill(MatrixND mat, final double value) { mat.map(new MapFunction() { public double apply(double v) { return value; @@ -259,11 +254,11 @@ } // /** - // * Cr�e une nouvelle matrice identit�. Une matrice identit� est une - // matrice - // * � 2 dimensions dont tous les �l�ments de la diagonal vaut 1 + // * Crée une nouvelle matrice identité. Une matrice identité est une + // * matrice à 2 dimensions dont tous les éléments de la diagonale + // * valent 1 // * @param size la taille de la matrice - // * @return une nouvelle matrice identit� + // * @return une nouvelle matrice identité // */ // static public MatrixND matrixId(int size){ // MatrixND result = new MatrixNDImpl(new int[]{size, size}); @@ -275,19 +270,19 @@ /** * Retourne la valeur la plus courrement rencontrer dans un tableau. si - * plusieurs valeurs ont le m�me nombre d'occurence la plus petite valeur - * est retourn�. + * plusieurs valeurs ont le même nombre d'occurence la plus petite valeur + * est retournée. * * @param tab le tableau de valeur * @return la valeur la plus nombreuse dans le tableau */ - static public double maxOccurence(double[] tab) { + public static double maxOccurence(double[] tab) { double[] tmp = new double[tab.length]; System.arraycopy(tab, 0, tmp, 0, tab.length); return maxOccurence1(tmp); } - static public double maxOccurence(float[] tab) { + public static double maxOccurence(float[] tab) { double[] tmp = new double[tab.length]; for (int i = 0; i < tab.length; i++) { tmp[i] = tab[i]; @@ -297,9 +292,9 @@ /** * le tableau en entre est trie durant l'execution de la methode, il est - * donc modifi� + * donc modifié */ - static protected double maxOccurence1(double[] tmp) { + protected static double maxOccurence1(double[] tmp) { if (tmp.length == 0) { throw new IllegalArgumentException("Array must be not empty"); } @@ -313,7 +308,7 @@ int count = 1; // la valeur la plus rencontrer double result = tmp[0]; - // la valeur que l'on vient de traiter pr�c�dement + // la valeur que l'on vient de traiter précédement double old = tmp[0]; // la valeur courante lu dans le tableaux double current = tmp[0]; Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIterator.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIterator.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIterator.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,8 +15,10 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatrixIterator.java +package org.codelutin.math.matrix; + +/** + * MatrixIterator. * * Created: 28 oct. 2004 * @@ -26,9 +28,6 @@ * Mise a jour: $Date$ * par : $Author$ */ - -package org.codelutin.math.matrix; - public interface MatrixIterator extends BasicMatrixIterator { // MatrixIterator /** Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIteratorImpl.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIteratorImpl.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIteratorImpl.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,8 +15,12 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatrixIteratorImpl.java +package org.codelutin.math.matrix; + +import java.util.List; + +/** + * MatrixIteratorImpl. * * Created: 28 oct. 2004 * @@ -26,11 +30,6 @@ * Mise a jour: $Date$ * par : $Author$ */ - -package org.codelutin.math.matrix; - -import java.util.List; - public class MatrixIteratorImpl implements MatrixIterator { // MatrixIteratorImpl protected BasicMatrixIterator iterator = null; Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,8 +15,18 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatrixND.java + + +package org.codelutin.math.matrix; + +import java.io.IOException; +import java.io.Reader; +import java.io.Serializable; +import java.io.Writer; +import java.util.List; + +/** + * MatrixND. * * Created: 29 oct. 2004 * @@ -26,15 +36,6 @@ * Mise a jour: $Date$ * par : $Author$ */ - -package org.codelutin.math.matrix; - -import java.io.IOException; -import java.io.Reader; -import java.io.Serializable; -import java.io.Writer; -import java.util.List; - public interface MatrixND extends Serializable, Cloneable { // MatrixND /** Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,8 +15,13 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatrixNDImpl.java +package org.codelutin.math.matrix; + +import java.util.Arrays; +import java.util.List; + +/** + * MatrixNDImpl. * * Created: 29 oct. 2004 * @@ -26,15 +31,9 @@ * Mise a jour: $Date$ * par : $Author$ */ - -package org.codelutin.math.matrix; - -import java.util.Arrays; -import java.util.List; - public class MatrixNDImpl extends AbstractMatrixND { // MatrixNDImpl - /** */ + /** serialVersionUID. */ private static final long serialVersionUID = 1L; protected BasicMatrix matrix = null; Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SemanticList.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SemanticList.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SemanticList.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,18 +15,6 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * SemanticList.java - * - * Created: 6 sept. 06 17:18:23 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - package org.codelutin.math.matrix; import java.util.AbstractList; @@ -37,7 +25,15 @@ import java.util.RandomAccess; /** + * SemanticList. + * + * Created: 6 sept. 06 17:18:23 + * * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ */ public class SemanticList<T> extends AbstractList<T> implements RandomAccess { @@ -49,8 +45,6 @@ } /* - * (non-Javadoc) - * * @see java.util.AbstractList#get(int) */ @Override @@ -60,8 +54,6 @@ } /* - * (non-Javadoc) - * * @see java.util.AbstractCollection#size() */ @Override @@ -71,8 +63,6 @@ } /* - * (non-Javadoc) - * * @see java.util.AbstractList#indexOf(java.lang.Object) */ @Override @@ -89,7 +79,7 @@ /** * @return */ - private Map getIndex() { + protected Map getIndex() { if (index == null) { index = new HashMap<Object, Integer>(); for (int i = 0; i < datas.size(); i++) { Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /*##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,18 +15,6 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * SubMatrix.java - * - * Created: 29 oct. 2004 - * - * @author Benjamin Poussin <poussin@codelutin.com> - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - package org.codelutin.math.matrix; import java.io.Serializable; @@ -39,12 +27,20 @@ * Pour l'instant une sous matrice a obligatoirement le meme nombre de dimension * que la matrice qu'elle contient. Elle permet juste de reduire le nombre * d'element d'une dimension. + * + * Created: 29 oct. 2004 + * + * @author Benjamin Poussin <poussin@codelutin.com> + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ */ public class SubMatrix extends AbstractMatrixND { // SubMatrix - /** */ - private static final long serialVersionUID = 1L; - + /** serialVersionUID. */ + private static final long serialVersionUID = 4092234115185263506L; + protected MatrixND matrix = null; protected DimensionConverter converter = null; @@ -183,9 +179,10 @@ * La conversion est le mapping d'un element vers un autre element */ protected class MappingConverter implements DimensionConverter { - /** */ - private static final long serialVersionUID = 1L; + /** serialVersionUID. */ + private static final long serialVersionUID = -6367416559713556559L; + protected int dim; protected int[] elem = null; @@ -203,7 +200,7 @@ return result; } else { throw new NoSuchElementException( - "L'indice est supérieur au nombre d'élement de la sous matrice pour cette dimension."); + "L'indice est supérieur au nombre d'élements de la sous matrice pour cette dimension."); } } } Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/Vector.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/Vector.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/Vector.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,8 +15,10 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * Vector.java +package org.codelutin.math.matrix; + +/** + * Vector. * * Created: 6 octobre 2005 02:51:12 CEST * @@ -26,9 +28,6 @@ * Last update: $Date$ * by : $Author$ */ - -package org.codelutin.math.matrix; - public interface Vector { // Vector public double getMaxOccurence(); Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,6 +1,6 @@ /* * *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -55,10 +55,18 @@ * TODO: Une methode permettant de retourne la sous matrice de la selection que * la matrice soit reprensentée en lineaire ou non. (avoir un mapping cellule de * table vers element de matrice + * + * Created: 29 oct. 2004 + * + * @author Benjamin Poussin <poussin@codelutin.com> + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ */ public class MatrixPanelEditor extends JPanel implements TableModelListener { // MatrixPanelEditor - /** */ + /** serialVersionUID */ private static final long serialVersionUID = 2097859265435050946L; private final static int DEFAULT_WIDTH = 150; @@ -148,7 +156,7 @@ initDimensionEdit(); } - JButton bEdit = null; + protected JButton bEdit = null; protected JButton getButtonEdit() { if (bEdit == null) { @@ -316,13 +324,6 @@ fireEvent(); } - /** - * @deprecated use setMatrix - */ - public void setMatrice(MatrixND m) throws MatrixException { - setMatrix(m); - } - public MatrixND getMatrix() { // if (m == null) { return m; @@ -334,13 +335,6 @@ } /** - * @deprecated use setMatrix - */ - public MatrixND getMatrice() { - return getMatrix(); - } - - /** * Enable the matrix to be edited. By default, the matrix is editable. */ public void setEnabled(boolean enabled) { @@ -367,10 +361,7 @@ } /* - * (non-Javadoc) - * - * @seejavax.swing.event.TableModelListener#tableChanged(javax.swing.event. - * TableModelEvent) + * @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent) */ public void tableChanged(TableModelEvent e) { fireEvent(); @@ -440,7 +431,6 @@ // final MatrixPanelEditor mp = ed; frame.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { System.exit(0); } Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java 2009-03-03 10:19:18 UTC (rev 120) @@ -15,8 +15,14 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatrixPanelEvent.java +package org.codelutin.math.matrix.gui; + +import java.util.EventObject; + +import org.codelutin.math.matrix.MatrixND; + +/** + * MatrixPanelEvent. * * Created: 21 mars 2006 14:53:25 * @@ -26,20 +32,11 @@ * Last update: $Date$ * by : $Author$ */ - -package org.codelutin.math.matrix.gui; - -import java.util.EventObject; - -import org.codelutin.math.matrix.MatrixND; - -/** - * @author poussin - * - */ - public class MatrixPanelEvent extends EventObject { + /** serialVersionUID. */ + private static final long serialVersionUID = 368165247855055401L; + /** * @param source */ Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelListener.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelListener.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelListener.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,8 +15,10 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatrixPanelListener.java +package org.codelutin.math.matrix.gui; + +/** + * MatrixPanelListener. * * Created: 21 mars 2006 14:54:05 * @@ -26,14 +28,6 @@ * Last update: $Date$ * by : $Author$ */ - -package org.codelutin.math.matrix.gui; - -/** - * @author poussin - * - */ - public interface MatrixPanelListener { /** Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,18 +15,6 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatrixPopupMenu.java - * - * Created: 22 mars 2006 12:11:46 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - package org.codelutin.math.matrix.gui; import static org.codelutin.i18n.I18n._; @@ -61,11 +49,19 @@ /** * Ajout d'un menu contextuel sur la matrice dans l'editeur * + * Created: 22 mars 2006 12:11:46 + * * @author ruchaud - * + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ */ public class MatrixPopupMenu extends JPopupMenu { + /** serialVersionUID. */ + private static final long serialVersionUID = 3349189688987885915L; + private MatrixPanelEditor matrixEditor; private JFileChooser fileChooser; Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModel.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModel.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModel.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,18 +15,6 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatrixTableModel.java - * - * Created: 22 mars 2006 12:53:22 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - package org.codelutin.math.matrix.gui; import javax.swing.table.TableCellRenderer; @@ -35,10 +23,16 @@ import org.codelutin.math.matrix.MatrixND; /** + * MatrixTableModel. + * + * Created: 22 mars 2006 12:53:22 + * * @author poussin - * + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ */ - public interface MatrixTableModel extends TableModel { public void setMatrix(MatrixND m); Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelLinear.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelLinear.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelLinear.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,18 +15,6 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatrixTableModelLinear.java - * - * Created: 22 mars 2006 12:11:46 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - package org.codelutin.math.matrix.gui; import java.awt.Color; @@ -49,19 +37,25 @@ import org.codelutin.math.matrix.MatrixND; /** + * MatrixTableModelLinear. + * + * Created: 22 mars 2006 12:11:46 + * * @author poussin - * + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ */ - public class MatrixTableModelLinear extends AbstractTableModel implements MatrixTableModel { - /** - * Logger for this class - */ - private static final Log log = LogFactory - .getLog(MatrixTableModelLinear.class); + /** serialVersionUID. */ + private static final long serialVersionUID = -7498520067143762434L; + /** Logger for this class. */ + private static Log log = LogFactory.getLog(MatrixTableModelLinear.class); + protected boolean enabled = true; protected MatrixND m = null; protected boolean showDefault = false; @@ -138,8 +132,6 @@ } /* - * (non-Javadoc) - * * @see javax.swing.table.TableModel#getRowCount() */ public int getRowCount() { @@ -147,8 +139,6 @@ } /* - * (non-Javadoc) - * * @see javax.swing.table.TableModel#getColumnCount() */ public int getColumnCount() { @@ -156,8 +146,6 @@ } /* - * (non-Javadoc) - * * @see javax.swing.table.TableModel#getValueAt(int, int) */ public Object getValueAt(int rowIndex, int columnIndex) { @@ -171,8 +159,6 @@ } /* - * (non-Javadoc) - * * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int) */ @Override @@ -181,10 +167,7 @@ } /* - * (non-Javadoc) - * - * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object, - * int, int) + * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object, int, int) */ @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { @@ -201,8 +184,6 @@ } /* - * (non-Javadoc) - * * @see javax.swing.table.AbstractTableModel#getColumnName(int) */ @Override @@ -235,6 +216,9 @@ class MatrixCellRenderer extends DefaultTableCellRenderer { + /** serialVersionUID. */ + private static final long serialVersionUID = 6537813058357761914L; + protected MatrixTableModelLinear model = null; protected Color bg = null; protected Color fg = null; @@ -249,9 +233,6 @@ border = getBorder(); } - /** */ - private static final long serialVersionUID = 6537813058357761914L; - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelND.java =================================================================== --- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelND.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelND.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /*##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,18 +15,6 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatrixTableModel.java - * - * Created: 21 mars 2006 19:01:27 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - package org.codelutin.math.matrix.gui; import java.awt.Color; @@ -47,20 +35,23 @@ import org.codelutin.math.matrix.MatrixND; /** - * @author poussin + * Extension de AbstractTableModel pour definir un TableModel avec une + * MatrixND comme support d'information. * + * TODO changer les 'matrice' en 'matrix', s'il y a des methodes public + * avec les nom 'matice' les laisser mais les mettres depreciées + * + * Created: 21 mars 2006 19:01:27 + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ */ +public class MatrixTableModelND extends AbstractTableModel implements MatrixTableModel { -public/* - * Extension de AbstractTableModel pour definir un TableModel avec une - * MatrixND comme support d'information. - * - * @todo changer les 'matrice' en 'matrix', s'il y a des methodes public - * avec les nom 'matice' les laisser mais les mettres depreciées - */ -class MatrixTableModelND extends AbstractTableModel implements MatrixTableModel { - - /** */ + /** serialVersionUID. */ private static final long serialVersionUID = 983978774901981167L; protected MatrixND m; @@ -318,6 +309,9 @@ class MatrixCellRenderer extends DefaultTableCellRenderer { + /** serialVersionUID. */ + private static final long serialVersionUID = 6537813058357761914L; + protected MatrixTableModelND model = null; protected Color bg = null; protected Color fg = null; @@ -332,9 +326,6 @@ border = getBorder(); } - /** */ - private static final long serialVersionUID = 6537813058357761914L; - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixBigTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixBigTest.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixBigTest.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,8 +15,10 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatriceTest.java +package org.codelutin.math.matrix; + +/** + * BasicMatrixBigTest. * * Created: 27 oct. 2004 * @@ -26,14 +28,11 @@ * Mise a jour: $Date$ * par : $Author$ */ +public class BasicMatrixBigTest extends BasicMatrixTest { // BasicMatrixBigTest -package org.codelutin.math.matrix; - -public class BasicMatrixBigTest extends BasicMatrixTest { // BasicMatrixTest - public MatrixFactory getFactory() throws Exception { return MatrixFactory.getInstance(FloatBigVector.class); } -} // BasicMatrixTest +} // BasicMatrixBigTest Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixTest.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixTest.java 2009-03-03 10:19:18 UTC (rev 120) @@ -15,8 +15,17 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatriceTest.java +package org.codelutin.math.matrix; + +import java.util.Arrays; +import java.util.NoSuchElementException; + +import org.apache.commons.lang.time.DurationFormatUtils; +import org.junit.Assert; +import org.junit.Test; + +/** + * BasicMatrixTest. * * Created: 27 oct. 2004 * @@ -26,96 +35,89 @@ * Mise a jour: $Date$ * par : $Author$ */ +public class BasicMatrixTest { // BasicMatrixTest -package org.codelutin.math.matrix; - -import java.util.Arrays; -import java.util.NoSuchElementException; - -import junit.framework.TestCase; - -import org.apache.commons.lang.time.DurationFormatUtils; - -public class BasicMatrixTest extends TestCase { // BasicMatrixTest - public MatrixFactory getFactory() throws Exception { return MatrixFactory.getInstance(); } + @Test public void testNew() throws Exception { BasicMatrix mat = null; try { mat = new BasicMatrix(getFactory(), null); - assertFalse(true); // on ne doit pas etre ici + Assert.assertFalse(true); // on ne doit pas etre ici } catch (NullPointerException eee) { - assertTrue(true); // mais on doit etre la + Assert.assertTrue(true); // mais on doit etre la } try { mat = new BasicMatrix(getFactory(), new int[] { 0 }); - assertFalse(true); // on ne doit pas etre ici + Assert.assertFalse(true); // on ne doit pas etre ici } catch (IllegalArgumentException eee) { - assertTrue(true); // mais on doit etre la + Assert.assertTrue(true); // mais on doit etre la } mat = new BasicMatrix(getFactory(), new int[] { 100 }); mat = new BasicMatrix(getFactory(), new int[] { 10, 1 }); - assertEquals(0.0, mat.getMaxOccurence()); + Assert.assertEquals(0.0, mat.getMaxOccurence(), 0); mat = new BasicMatrix(getFactory(), new int[] { 10, 10, 10, 10 }); try { mat = new BasicMatrix(getFactory(), new int[] { -10 }); - assertFalse(true); // on ne doit pas etre ici + Assert.assertFalse(true); // on ne doit pas etre ici } catch (IllegalArgumentException eee) { - assertTrue(true); // mais on doit etre la + Assert.assertTrue(true); // mais on doit etre la } try { mat = new BasicMatrix(getFactory(), new int[] { 10, 20, -10, 20 }); - assertFalse(true); // on ne doit pas etre ici + Assert.assertFalse(true); // on ne doit pas etre ici } catch (IllegalArgumentException eee) { - assertTrue(true); // mais on doit etre la + Assert.assertTrue(true); // mais on doit etre la } } + @Test public void testDimension() throws Exception { BasicMatrix mat = null; mat = new BasicMatrix(getFactory(), new int[] { 1, 10, 30, 5 }); - assertEquals(4, mat.getNbDim()); - assertEquals(1, mat.getDim(0)); - assertEquals(10, mat.getDim(1)); - assertEquals(30, mat.getDim(2)); - assertEquals(5, mat.getDim(3)); + Assert.assertEquals(4, mat.getNbDim()); + Assert.assertEquals(1, mat.getDim(0)); + Assert.assertEquals(10, mat.getDim(1)); + Assert.assertEquals(30, mat.getDim(2)); + Assert.assertEquals(5, mat.getDim(3)); try { mat.getDim(-3); - assertFalse(true); // on ne doit pas etre ici + Assert.assertFalse(true); // on ne doit pas etre ici } catch (IndexOutOfBoundsException eee) { - assertTrue(true); // mais on doit etre la + Assert.assertTrue(true); // mais on doit etre la } try { mat.getDim(4); - assertFalse(true); // on ne doit pas etre ici + Assert.assertFalse(true); // on ne doit pas etre ici } catch (IndexOutOfBoundsException eee) { - assertTrue(true); // mais on doit etre la + Assert.assertTrue(true); // mais on doit etre la } } + @Test public void testGetSet() throws Exception { BasicMatrix mat = null; // test avec la plus petit BasicMatrix possible mat = new BasicMatrix(getFactory(), new int[] { 1 }); // test la valeur par defaut doit etre 0 - assertEquals(0, mat.getValue(new int[] { 0 }), 0); + Assert.assertEquals(0, mat.getValue(new int[] { 0 }), 0); mat.setValue(new int[] { 0 }, 30); - assertEquals(30, mat.getValue(new int[] { 0 }), 0); + Assert.assertEquals(30, mat.getValue(new int[] { 0 }), 0); // acces a un element qui n'existe pas try { mat.getValue(new int[] { 1 }); - assertFalse(true); // on ne doit pas etre ici + Assert.assertFalse(true); // on ne doit pas etre ici } catch (NoSuchElementException eee) { - assertTrue(true); // mais on doit etre la + Assert.assertTrue(true); // mais on doit etre la } mat = new BasicMatrix(getFactory(), new int[] { 1, 10, 5 }); @@ -134,37 +136,39 @@ mat.setValue(new int[] { 0, 2, 2 }, 22); mat.setValue(new int[] { 0, 9, 4 }, 98); mat.setValue(new int[] { 0, 4, 2 }, 97); - assertEquals(0, mat.getValue(new int[] { 0, 0, 0 }), 0); - assertEquals(98, mat.getValue(new int[] { 0, 9, 4 }), 0); - assertEquals(97, mat.getValue(new int[] { 0, 4, 2 }), 0); + Assert.assertEquals(0, mat.getValue(new int[] { 0, 0, 0 }), 0); + Assert.assertEquals(98, mat.getValue(new int[] { 0, 9, 4 }), 0); + Assert.assertEquals(97, mat.getValue(new int[] { 0, 4, 2 }), 0); // System.out.println(mat.toString()); // acces a un element qui n'existe pas try { mat.setValue(new int[] { 0, 9, 5 }, 44); - assertFalse(true); // on ne doit pas etre ici + Assert.assertFalse(true); // on ne doit pas etre ici } catch (NoSuchElementException eee) { - assertTrue(true); // mais on doit etre la + Assert.assertTrue(true); // mais on doit etre la } } + @Test public void testEquals() throws Exception { 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); + Assert.assertEquals(m1, m2); m1.setValue(new int[] { 1, 2, 1, 2 }, 123); m2.setValue(new int[] { 1, 2, 1, 2 }, 123); - assertEquals(m1, m2); + Assert.assertEquals(m1, m2); m1.setValue(new int[] { 1, 0, 1, 0 }, 321); - assertFalse(m1.equals(m2)); + Assert.assertFalse(m1.equals(m2)); } + @Test public void testIterator() throws Exception { int[][] val27 = new int[][] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 }, @@ -184,7 +188,7 @@ cpt++; } - assertEquals(27, cpt); + Assert.assertEquals(27, cpt); cpt = 0; BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 1 }); @@ -194,15 +198,16 @@ cpt++; } - assertEquals(1, cpt); + Assert.assertEquals(1, cpt); } - MapFunction f = new MapFunction() { + protected MapFunction f = new MapFunction() { public double apply(double value) { return value + 2; } }; + @Test public void testPerfLineaire() throws Exception { long time = System.nanoTime(); BasicMatrix m1 = new BasicMatrix(getFactory(), new int[] { 30, 30, 30, @@ -214,6 +219,7 @@ "s'.'S")); } + @Test public void testPerfCoordonnee() throws Exception { long time = System.nanoTime(); BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 30, 30, 30, @@ -245,6 +251,7 @@ } + @Test public void testPerfCoordonnee2() throws Exception { long time = System.nanoTime(); BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 30, 30, 30, @@ -276,6 +283,7 @@ } + @Test public void testPerfCoordonnee4() throws Exception { long time = System.nanoTime(); BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 30, 30, 30, Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/FloatVectorTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/FloatVectorTest.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/FloatVectorTest.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,8 +15,15 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * FloatVectorTest.java +package org.codelutin.math.matrix; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assert; +import org.junit.Test; + +/** + * FloatVectorTest. * * Created: 6 octobre 2005 01:54:49 CEST * @@ -26,27 +33,26 @@ * Last update: $Date$ * by : $Author$ */ +public class FloatVectorTest { // FloatVectorTest -package org.codelutin.math.matrix; - -import junit.framework.TestCase; - -public class FloatVectorTest extends TestCase { // FloatVectorTest - + /** to use log facility, just put in your code: log.info(\"...\"); */ + private static Log log = LogFactory.getLog(FloatVectorTest.class); + + @Test public void testAll() throws Exception { FloatVector v = new FloatVector(16); - assertEquals(0.0, v.getMaxOccurence()); + Assert.assertEquals(0.0, v.getMaxOccurence(), 0); v.setValue(0, 1); - assertEquals(1.0, v.getValue(0)); + Assert.assertEquals(1.0, v.getValue(0), 0); v.setValue(15, 16); - assertEquals(16.0, v.getValue(15)); + Assert.assertEquals(16.0, v.getValue(15), 0); - assertEquals(2, v.positionSize); + Assert.assertEquals(2, v.positionSize); v.setValue(0, 0); - assertEquals(0.0, v.getValue(0)); - assertEquals(1, v.positionSize); + Assert.assertEquals(0.0, v.getValue(0), 0); + Assert.assertEquals(1, v.positionSize); v.setValue(0, 4); v.setValue(1, 4); @@ -55,27 +61,30 @@ v.setValue(4, 4); v.setValue(5, 4); v.setValue(6, 4); - assertEquals(0.0, v.getMaxOccurence()); + Assert.assertEquals(0.0, v.getMaxOccurence(), 0); v.setValue(8, 4); - assertEquals(4.0, v.getMaxOccurence()); + Assert.assertEquals(4.0, v.getMaxOccurence(), 0); v.setValue(0, 0); - assertEquals(0.0, v.getMaxOccurence()); + Assert.assertEquals(0.0, v.getMaxOccurence(), 0); try { v.getValue(-1); - assertTrue(false); - } catch (IllegalArgumentException eee) { - assertTrue(true); + Assert.fail("An exception must be thrown"); + } catch (IllegalArgumentException e) { + if (log.isDebugEnabled()) { + log.debug("Exception normally thrown", e); + } } try { v.getValue(20); - assertTrue(false); - } catch (IllegalArgumentException eee) { - assertTrue(true); + Assert.fail("An exception must be thrown"); + } catch (IllegalArgumentException e) { + if (log.isDebugEnabled()) { + log.debug("Exception normally thrown", e); + } } } } // FloatVectorTest - Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/ImportExportMatrixTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/ImportExportMatrixTest.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/ImportExportMatrixTest.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,6 +1,5 @@ -/* - * *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin +/* *##% lutinmatrix + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -24,26 +23,32 @@ import java.util.Arrays; import java.util.List; -import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; /** - * Test de l'import et export CSV + * Test de l'import et export CSV. * * @author ruchaud - * + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ */ -public class ImportExportMatrixTest extends TestCase { +public class ImportExportMatrixTest { - private MatrixND mat1D; - private MatrixND mat2D; - private MatrixND mat2DSemantics; + protected MatrixND mat1D; + protected MatrixND mat2D; + protected MatrixND mat2DSemantics; public MatrixFactory getFactory() throws Exception { return MatrixFactory.getInstance(DoubleVector.class); } - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { mat1D = new MatrixNDImpl(getFactory(), new int[] { 10 }); mat1D.setValue(new int[] { 0 }, 0); mat1D.setValue(new int[] { 1 }, 1); @@ -70,6 +75,7 @@ sem1, sem2 }, new String[] { "dim1", "dim2" }); } + @Test public void testImport() throws IOException { 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" @@ -77,19 +83,20 @@ 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); + Assert.assertEquals(mat2D.getValue(0, 0), 5.0E-7, 0); + Assert.assertEquals(mat2D.getValue(1, 2), 7.0, 0); + Assert.assertEquals(mat2D.getValue(2, 2), 8.0, 0); + Assert.assertEquals(mat2D.getValue(1, 8), 4.0, 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); + Assert.assertEquals(mat2D.getValue(1, 1), 5.0E-7, 0); + Assert.assertEquals(mat2D.getValue(2, 3), 7.0, 0); + Assert.assertEquals(mat2D.getValue(3, 3), 8.0, 0); + Assert.assertEquals(mat2D.getValue(2, 9), 4.0, 0); } + @Test public void testExport() throws IOException { testExport(mat1D, false); testExport(mat2D, false); @@ -101,7 +108,8 @@ testExport(mat2DSemantics, true); } - private void testExport(MatrixND matrixND, boolean withSemantics) + @Ignore + protected void testExport(MatrixND matrixND, boolean withSemantics) throws IOException { StringWriter writer = new StringWriter(); matrixND.exportCSV(writer, withSemantics); @@ -112,15 +120,16 @@ StringWriter readerToWriter = new StringWriter(); matrixND.exportCSV(readerToWriter, withSemantics); - assertEquals(writer.toString(), readerToWriter.toString()); + Assert.assertEquals(writer.toString(), readerToWriter.toString()); } + @Test public void testSupport() throws Exception { - assertEquals(true, new MatrixNDImpl(getFactory(), new int[] { 1 }) + Assert.assertEquals(true, new MatrixNDImpl(getFactory(), new int[] { 1 }) .isSupportedCSV()); - assertEquals(true, new MatrixNDImpl(getFactory(), new int[] { 2, 2 }) + Assert.assertEquals(true, new MatrixNDImpl(getFactory(), new int[] { 2, 2 }) .isSupportedCSV()); - assertEquals(false, new MatrixNDImpl(getFactory(), + Assert.assertEquals(false, new MatrixNDImpl(getFactory(), new int[] { 3, 3, 3 }).isSupportedCSV()); } } Deleted: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,82 +0,0 @@ -/* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ - -/* * - * MatrixEncoderDecoderTest.java - * - * Created: 31 oct. 2004 - * - * @author Benjamin Poussin <poussin@codelutin.com> - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - -package org.codelutin.math.matrix; - -import junit.framework.TestCase; - -/** - * FIXME comment test since lutinxml is not used any. - * - * @author poussin - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class MatrixEncoderDecoderTest extends TestCase { // MatrixEncoderDecoderTest - - public void testDummy() { - // dummy test for hudson compilation work, perhaps remove this class if we put something about XML in TODO - assertTrue(true); - } - - /* - * public MatrixFactory getFactory() throws Exception { return - * MatrixFactory.getInstance(); } - * - * protected void subtestEncoderDecoder(MatrixND mat) throws Exception { // - * encodage en XML String xml = MatrixHelper.encodeToXML(mat); // decodage - * depuis le XML MatrixND mat2 = MatrixHelper.decodeFromXML(xml); // - * reencodage de la matrice resultat String xml2 = - * MatrixHelper.encodeToXML(mat2); // on verifie que les 2 matrices sont - * egals et leur representation // XML aussi assertEquals(mat, mat2); - * assertEquals(xml, xml2); } - * - * public void testEncoderDecoder() 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"}); - * - * MatrixND mat = null; - * - * mat = getFactory().create("Ma mat", new int[]{3,3,3}); - * subtestEncoderDecoder(mat); - * - * 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 = - * 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); } - */ - -} // MatrixEncoderDecoderTest - Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,8 +15,17 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatrixHelperTest.java +package org.codelutin.math.matrix; + +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assert; +import org.junit.Test; + +/** + * MatrixHelperTest. * * Created: 29 oct. 2004 * @@ -26,68 +35,71 @@ * Mise a jour: $Date$ * par : $Author$ */ +public class MatrixHelperTest { // MatrixHelperTest -package org.codelutin.math.matrix; - -import java.util.List; - -import junit.framework.TestCase; - -public class MatrixHelperTest extends TestCase { // MatrixHelperTest - + /** to use log facility, just put in your code: log.info(\"...\"); */ + private static Log log = LogFactory.getLog(MatrixHelperTest.class); + public MatrixFactory getFactory() throws Exception { return MatrixFactory.getInstance(); } + @Test public void testCoordinatesToString() throws Exception { - assertEquals("1", MatrixHelper.coordinatesToString(new int[] { 1 })); - assertEquals("2,3,4,5", MatrixHelper.coordinatesToString(new int[] { 2, + Assert.assertEquals("1", MatrixHelper.coordinatesToString(new int[] { 1 })); + Assert.assertEquals("2,3,4,5", MatrixHelper.coordinatesToString(new int[] { 2, 3, 4, 5 })); - assertEquals("2,3,4,5,234", MatrixHelper.coordinatesToString(new int[] { + Assert.assertEquals("2,3,4,5,234", MatrixHelper.coordinatesToString(new int[] { 2, 3, 4, 5, 234 })); - assertEquals("a", MatrixHelper + Assert.assertEquals("a", MatrixHelper .coordinatesToString(new String[] { "a" })); - assertEquals("a,b,n,m", MatrixHelper.coordinatesToString(new String[] { + Assert.assertEquals("a,b,n,m", MatrixHelper.coordinatesToString(new String[] { "a", "b", "n", "m" })); - assertEquals("a,b,f,e,aze", + Assert.assertEquals("a,b,f,e,aze", MatrixHelper.coordinatesToString(new String[] { "a", "b", "f", "e", "aze" })); } + @Test public void testSameDimension() throws Exception { - assertTrue(MatrixHelper.sameDimension(new int[] { 1 }, new int[] { 1 })); - assertTrue(MatrixHelper.sameDimension(new int[] { 1, 2 }, new int[] { + Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1 }, new int[] { 1 })); + Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1, 2 }, new int[] { 1, 2 })); - assertTrue(MatrixHelper.sameDimension(new int[] { 1, 324, 3 }, + Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1, 324, 3 }, new int[] { 1, 324, 3 })); } + @Test public void testDimensionToSemantics() throws Exception { // TODO faire un test pour dimensionToSemantics } + @Test public void testSemanticsToDimension() throws Exception { // TODO faire un test pour semanticsToDimension } + @Test public void testFill() throws Exception { MatrixND mat = getFactory().create(new int[] { 3, 3 }); MatrixHelper.fill(mat, 4); - assertEquals(4, mat.getValue(1, 1), 0); + Assert.assertEquals(4, mat.getValue(1, 1), 0); } + @Test public void testMatrixId() throws Exception { 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); - assertEquals(1, mat.getValue(1, 1), 0); - assertEquals(1, mat.getValue(2, 2), 0); - assertEquals(1, mat.getValue(3, 3), 0); + Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 4, 4 }, mat.getDim())); + Assert.assertEquals(0, mat.getValue(1, 2), 0); + Assert.assertEquals(1, mat.getValue(0, 0), 0); + Assert.assertEquals(1, mat.getValue(1, 1), 0); + Assert.assertEquals(1, mat.getValue(2, 2), 0); + Assert.assertEquals(1, mat.getValue(3, 3), 0); } + @Test public void testToList() throws Exception { MatrixND mat1 = getFactory().create(new int[] { 3, 2, 1 }); mat1.setValue(0, 0, 0, -1.0E-7); @@ -101,49 +113,52 @@ System.out.println(l); System.out.println(l2); - assertEquals(l, l2); + Assert.assertEquals(l, l2); } + @Test public void testMaxOccurence() throws Exception { double[] val = new double[5]; - assertEquals(0, MatrixHelper.maxOccurence(val), 0); + Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0); val[2] = -1; - assertEquals(0, MatrixHelper.maxOccurence(val), 0); + Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0); val[0] = -1; - assertEquals(0, MatrixHelper.maxOccurence(val), 0); + Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0); val[1] = -1; - assertEquals(-1, MatrixHelper.maxOccurence(val), 0); + Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0); val[4] = -3; - assertEquals(-1, MatrixHelper.maxOccurence(val), 0); + Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0); val[3] = 3; - assertEquals(-1, MatrixHelper.maxOccurence(val), 0); + Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0); val = new double[6]; - assertEquals(0, MatrixHelper.maxOccurence(val), 0); + Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0); val[2] = -1; - assertEquals(0, MatrixHelper.maxOccurence(val), 0); + Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0); val[0] = -1; - assertEquals(0, MatrixHelper.maxOccurence(val), 0); + Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0); val[1] = -1; - assertEquals(-1, MatrixHelper.maxOccurence(val), 0); + Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0); val[4] = -3; - assertEquals(-1, MatrixHelper.maxOccurence(val), 0); + Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0); val[3] = -3; - assertEquals(-1, MatrixHelper.maxOccurence(val), 0); + Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0); val[5] = -3; - assertEquals(-3, MatrixHelper.maxOccurence(val), 0); + Assert.assertEquals(-3, MatrixHelper.maxOccurence(val), 0); val = new double[0]; try { MatrixHelper.maxOccurence(val); - assertFalse(true); // on ne passe pas ici - } catch (IllegalArgumentException eee) { - assertTrue(true); // on passe ici + Assert.fail("AN exception must be thrown"); + } catch (IllegalArgumentException e) { + if (log.isDebugEnabled()) { + log.debug("Exception normally thrown", e); + } } } Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,17 +15,6 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * AppTestCase.java - * - * Created: 10 mai 2004 - * - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - package org.codelutin.math.matrix; import java.io.IOException; @@ -36,17 +25,28 @@ import java.util.List; import java.util.Stack; -import junit.framework.TestCase; - import org.apache.commons.lang.time.DurationFormatUtils; import org.codelutin.util.StringUtil; +import org.junit.Assert; +import org.junit.Test; -public class MatrixNDTest extends TestCase { +/* * + * AppTestCase.java + * + * Created: 10 mai 2004 + * + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class MatrixNDTest { public MatrixFactory getFactory() throws Exception { return MatrixFactory.getInstance(DoubleVector.class); } + @Test public void testNew() throws Exception { List s1 = Arrays.asList(new String[] { "a", "b", "c" }); List s2 = Arrays.asList(new String[] { "e", "f", "g" }); @@ -60,10 +60,11 @@ mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, new String[] { "dim abc", "dim efg", "dim klm" }); - assertEquals(0.0, mat.getMaxOccurence()); + Assert.assertEquals(0.0, mat.getMaxOccurence(), 0); } + @Test public void testSemantique() throws Exception { List s1 = Arrays.asList(new String[] { "a", "b", "c" }); List s2 = Arrays.asList(new String[] { "e", "f", "g" }); @@ -73,18 +74,19 @@ mat = getFactory().create(new int[] { 3, 3, 3 }); - assertTrue(null == mat.getSemantics(1).get(1)); + Assert.assertNull(mat.getSemantics(1).get(1)); mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }); // la matrice doit avoir ca propre copie des semantiques s2.set(1, "pas bon"); - assertEquals("f", mat.getSemantics(1).get(1)); + Assert.assertEquals("f", mat.getSemantics(1).get(1)); mat.setSemantics(1, s1); - assertEquals("b", mat.getSemantics(1).get(1)); + Assert.assertEquals("b", mat.getSemantics(1).get(1)); } + @Test public void testName() throws Exception { List s1 = Arrays.asList(new String[] { "a", "b", "c" }); List s2 = Arrays.asList(new String[] { "e", "f", "g" }); @@ -95,15 +97,16 @@ mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, new String[] { "dim abc", "dim efg", "dim klm" }); - assertEquals("Ma mat", mat.getName()); + Assert.assertEquals("Ma mat", mat.getName()); mat.setName("Renamed"); - assertEquals("Renamed", mat.getName()); + Assert.assertEquals("Renamed", mat.getName()); - assertEquals("dim abc", mat.getDimensionName(0)); + Assert.assertEquals("dim abc", mat.getDimensionName(0)); mat.setDimensionName(0, "dim renamed"); - assertEquals("dim renamed", mat.getDimensionName(0)); + Assert.assertEquals("dim renamed", mat.getDimensionName(0)); } + @Test public void testGetSet() throws Exception { List s1 = Arrays.asList(new String[] { "a", "b", "c" }); List s2 = Arrays.asList(new String[] { "e", "f", "g" }); @@ -115,12 +118,13 @@ new String[] { "dim abc", "dim efg", "dim klm" }); mat.setValue(1, 1, 1, 34); - assertEquals(34, mat.getValue("b", "f", "l"), 0); + Assert.assertEquals(34, mat.getValue("b", "f", "l"), 0); mat.setValue("a", "f", "m", 22); - assertEquals(22, mat.getValue(0, 1, 2), 0); + Assert.assertEquals(22, mat.getValue(0, 1, 2), 0); } + @Test public void testIterator() throws Exception { int[][] val27 = new int[][] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 }, { 0, 1, 0 }, { 0, 1, 1 }, { 0, 1, 2 }, { 0, 2, 0 }, @@ -153,13 +157,15 @@ int cpt = 0; for (MatrixIterator i = mat.iterator(); i.hasNext();) { i.next(); - assertTrue(Arrays.equals(val27[cpt], i.getCoordinates())); - assertTrue(Arrays.equals(vals27[cpt], i.getSemanticsCoordinates())); + Assert.assertTrue(Arrays.equals(val27[cpt], i.getCoordinates())); + Assert.assertTrue(Arrays.equals(vals27[cpt], i + .getSemanticsCoordinates())); cpt++; } - assertEquals(27, cpt); + Assert.assertEquals(27, cpt); } + @Test public void testAdd() throws Exception { List s1 = Arrays.asList(new String[] { "a", "b", "c" }); List s2 = Arrays.asList(new String[] { "e", "f", "g" }); @@ -177,11 +183,12 @@ mat1.add(mat2); - assertEquals(29, mat1.getValue(0, 0, 0), 0); - assertEquals(29, mat1.getValue(1, 2, 0), 0); - assertEquals(29, mat1.getValue(2, 2, 2), 0); + Assert.assertEquals(29, mat1.getValue(0, 0, 0), 0); + Assert.assertEquals(29, mat1.getValue(1, 2, 0), 0); + Assert.assertEquals(29, mat1.getValue(2, 2, 2), 0); } + @Test public void testMinus() throws Exception { List s1 = Arrays.asList(new String[] { "a", "b", "c" }); List s2 = Arrays.asList(new String[] { "e", "f", "g" }); @@ -199,11 +206,12 @@ mat1.minus(mat2); - assertEquals(-23, mat1.getValue(0, 0, 0), 0); - assertEquals(-23, mat1.getValue(1, 2, 0), 0); - assertEquals(-23, mat1.getValue(2, 2, 2), 0); + Assert.assertEquals(-23, mat1.getValue(0, 0, 0), 0); + Assert.assertEquals(-23, mat1.getValue(1, 2, 0), 0); + Assert.assertEquals(-23, mat1.getValue(2, 2, 2), 0); } + @Test public void testEquals() throws Exception { List s1 = Arrays.asList(new String[] { "a", "b", "c" }); List s2 = Arrays.asList(new String[] { "e", "f", "g" }); @@ -225,9 +233,10 @@ mat1.add(mat2); - assertEquals(mat1, mat3); + Assert.assertEquals(mat1, mat3); } + @Test public void testsumOverDim() throws Exception { List s1 = Arrays.asList(new String[] { "a", "b", "c" }); List s2 = Arrays.asList(new String[] { "e", "f", "g" }); @@ -242,35 +251,35 @@ mi.setValue(++i); } - assertEquals(mat, mat2); + Assert.assertEquals(mat, mat2); mat2 = mat.sumOverDim(1, 0); - assertEquals(mat, mat2); + Assert.assertEquals(mat, mat2); mat2 = mat.sumOverDim(1, 1); - assertEquals(mat, mat2); + Assert.assertEquals(mat, mat2); mat2 = mat.sumOverDim(1, 2); - assertEquals(2, mat2.getDim(1)); - assertEquals(3, mat2.getValue(0, 0), 0); - assertEquals(7, mat2.getValue(0, 1), 0); - assertEquals(11, mat2.getValue(1, 0), 0); - assertEquals(15, mat2.getValue(1, 1), 0); - assertEquals(19, mat2.getValue(2, 0), 0); - assertEquals(23, mat2.getValue(2, 1), 0); - assertEquals(27, mat2.getValue(3, 0), 0); - assertEquals(31, mat2.getValue(3, 1), 0); + Assert.assertEquals(2, mat2.getDim(1)); + Assert.assertEquals(3, mat2.getValue(0, 0), 0); + Assert.assertEquals(7, mat2.getValue(0, 1), 0); + Assert.assertEquals(11, mat2.getValue(1, 0), 0); + Assert.assertEquals(15, mat2.getValue(1, 1), 0); + Assert.assertEquals(19, mat2.getValue(2, 0), 0); + Assert.assertEquals(23, mat2.getValue(2, 1), 0); + Assert.assertEquals(27, mat2.getValue(3, 0), 0); + Assert.assertEquals(31, mat2.getValue(3, 1), 0); mat2 = mat.sumOverDim(1, 3); - assertEquals(1, mat2.getDim(1)); - assertEquals(6, mat2.getValue(0, 0), 0); - assertEquals(18, mat2.getValue(1, 0), 0); - assertEquals(30, mat2.getValue(2, 0), 0); - assertEquals(42, mat2.getValue(3, 0), 0); + Assert.assertEquals(1, mat2.getDim(1)); + Assert.assertEquals(6, mat2.getValue(0, 0), 0); + Assert.assertEquals(18, mat2.getValue(1, 0), 0); + Assert.assertEquals(30, mat2.getValue(2, 0), 0); + Assert.assertEquals(42, mat2.getValue(3, 0), 0); mat2 = mat.sumOverDim(1, 4); - assertEquals(1, mat2.getDim(1)); - assertEquals(10, mat2.getValue(0, 0), 0); - assertEquals(26, mat2.getValue(1, 0), 0); - assertEquals(42, mat2.getValue(2, 0), 0); - assertEquals(58, mat2.getValue(3, 0), 0); + Assert.assertEquals(1, mat2.getDim(1)); + Assert.assertEquals(10, mat2.getValue(0, 0), 0); + Assert.assertEquals(26, mat2.getValue(1, 0), 0); + Assert.assertEquals(42, mat2.getValue(2, 0), 0); + Assert.assertEquals(58, mat2.getValue(3, 0), 0); mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 }, new String[] { "dim abc", "dim efg", "dim klm" }); @@ -279,12 +288,12 @@ mat.setValue(0, 0, 0, 2); mat.setValue(2, 2, 2, 4); mat = mat.sumOverDim(1); - assertTrue(MatrixHelper.sameDimension(new int[] { 3, 1, 3 }, mat + Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 3, 1, 3 }, mat .getDim())); - assertEquals(8, mat.getValue(0, 0, 0), 0); - assertEquals(9, mat.getValue(2, 0, 1), 0); - assertEquals(10, mat.getValue(2, 0, 2), 0); + Assert.assertEquals(8, mat.getValue(0, 0, 0), 0); + Assert.assertEquals(9, mat.getValue(2, 0, 1), 0); + Assert.assertEquals(10, mat.getValue(2, 0, 2), 0); mat = getFactory().create(new int[] { 6, 6, 6 }); @@ -297,14 +306,15 @@ mat.setValue(0, 5, 0, 5); mat = mat.sumOverDim(1, 3); - assertTrue(MatrixHelper.sameDimension(new int[] { 6, 2, 6 }, mat + Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 6, 2, 6 }, mat .getDim())); - assertEquals(3, mat.getValue(0, 0, 0), 0); - assertEquals(12, mat.getValue(0, 1, 0), 0); - assertEquals(9, mat.getValue(1, 1, 5), 0); - assertEquals(9, mat.getValue(5, 0, 3), 0); + Assert.assertEquals(3, mat.getValue(0, 0, 0), 0); + Assert.assertEquals(12, mat.getValue(0, 1, 0), 0); + Assert.assertEquals(9, mat.getValue(1, 1, 5), 0); + Assert.assertEquals(9, mat.getValue(5, 0, 3), 0); } + @Test public void testTranspose() throws Exception { MatrixND mat = null; @@ -315,10 +325,10 @@ mat.setValue(1, 0, 46); mat = mat.transpose(); - assertEquals(56, mat.getValue(3, 1), 0); - assertEquals(34, mat.getValue(2, 0), 0); - assertEquals(64, mat.getValue(1, 0), 0); - assertEquals(46, mat.getValue(0, 1), 0); + Assert.assertEquals(56, mat.getValue(3, 1), 0); + Assert.assertEquals(34, mat.getValue(2, 0), 0); + Assert.assertEquals(64, mat.getValue(1, 0), 0); + Assert.assertEquals(46, mat.getValue(0, 1), 0); mat = getFactory().create(new int[] { 4 }); mat.setValue(1, 56); @@ -327,12 +337,13 @@ mat.setValue(0, 46); mat = mat.transpose(); - assertEquals(56, mat.getValue(0, 1), 0); - assertEquals(34, mat.getValue(0, 2), 0); - assertEquals(64, mat.getValue(0, 3), 0); - assertEquals(46, mat.getValue(0, 0), 0); + Assert.assertEquals(56, mat.getValue(0, 1), 0); + Assert.assertEquals(34, mat.getValue(0, 2), 0); + Assert.assertEquals(64, mat.getValue(0, 3), 0); + Assert.assertEquals(46, mat.getValue(0, 0), 0); } + @Test public void testMults() throws Exception { List s1 = Arrays.asList(new String[] { "a", "b", "c" }); List s2 = Arrays.asList(new String[] { "e", "f", "g" }); @@ -351,16 +362,17 @@ mat1.mults(3); mat2.mults(0); - assertEquals(9, mat1.getValue(0, 0, 0), 0); - assertEquals(9, mat1.getValue(1, 2, 0), 0); - assertEquals(0, mat2.getValue(2, 2, 2), 0); + Assert.assertEquals(9, mat1.getValue(0, 0, 0), 0); + Assert.assertEquals(9, mat1.getValue(1, 2, 0), 0); + Assert.assertEquals(0, mat2.getValue(2, 2, 2), 0); MatrixND mat0 = getFactory().create(new int[] { 4, 4 }); MatrixND matId = getFactory().matrixId(4); matId.mults(0); - assertEquals(mat0, matId); + Assert.assertEquals(mat0, matId); } + @Test public void testDivs() throws Exception { List s1 = Arrays.asList(new String[] { "a", "b", "c" }); List s2 = Arrays.asList(new String[] { "e", "f", "g" }); @@ -379,11 +391,12 @@ mat1.divs(3); mat2.divs(4); - assertEquals(1, mat1.getValue(0, 0, 0), 0); - assertEquals(6.5, mat2.getValue(1, 2, 0), 0); - assertEquals(6.5, mat2.getValue(2, 2, 2), 0); + Assert.assertEquals(1, mat1.getValue(0, 0, 0), 0); + Assert.assertEquals(6.5, mat2.getValue(1, 2, 0), 0); + Assert.assertEquals(6.5, mat2.getValue(2, 2, 2), 0); } + @Test public void testPaste() throws Exception { MatrixND mat1 = getFactory().create(new int[] { 6, 7, 8 }); @@ -394,12 +407,13 @@ mat1.paste(new int[] { 3, 0, 4 }, mat2); - assertEquals(3, mat1.getValue(0, 0, 0), 0); - assertEquals(26, mat1.getValue(3, 0, 4), 0); - assertEquals(26, mat1.getValue(4, 1, 5), 0); - assertEquals(3, mat1.getValue(5, 2, 6), 0); + Assert.assertEquals(3, mat1.getValue(0, 0, 0), 0); + Assert.assertEquals(26, mat1.getValue(3, 0, 4), 0); + Assert.assertEquals(26, mat1.getValue(4, 1, 5), 0); + Assert.assertEquals(3, mat1.getValue(5, 2, 6), 0); } + @Test public void testSumOverDim() throws Exception { MatrixND mat = null; @@ -425,9 +439,10 @@ mat = mat.sumOverDim(0, 1, 3); mat = mat.sumOverDim(0, 2, 2); - assertTrue(result.equalsValues(mat)); + Assert.assertTrue(result.equalsValues(mat)); } + @Test public void testReduce() throws Exception { MatrixND mat = null; @@ -436,25 +451,25 @@ MatrixHelper.fill(mat, 3); mat = mat.sumOverDim(1); - assertEquals(21, mat.getValue(0, 0, 0), 0); + Assert.assertEquals(21, mat.getValue(0, 0, 0), 0); mat = mat.reduce(); - 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); + Assert.assertEquals(2, mat.getNbDim()); + Assert.assertEquals(6, mat.getDim(0)); + Assert.assertEquals(8, mat.getDim(1)); + Assert.assertEquals(21, mat.getValue(0, 0), 0); + Assert.assertEquals(21, mat.getValue(5, 7), 0); mat = getFactory().create(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); + Assert.assertEquals(104, mat.getValue(0, 0, 0), 0); mat = mat.reduce(); - assertEquals(1, mat.getNbDim()); - assertEquals(2, mat.getDim(0)); - assertEquals(104, mat.getValue(0), 0); - assertEquals(104, mat.getValue(1), 0); + Assert.assertEquals(1, mat.getNbDim()); + Assert.assertEquals(2, mat.getDim(0)); + Assert.assertEquals(104, mat.getValue(0), 0); + Assert.assertEquals(104, mat.getValue(1), 0); mat = getFactory().create(new int[] { 2, 2, 2 }); MatrixHelper.fill(mat, 6); @@ -462,36 +477,36 @@ mat = mat.sumOverDim(1); mat = mat.sumOverDim(2); mat = mat.sumOverDim(0); - assertEquals(48, mat.getValue(0, 0, 0), 0); + Assert.assertEquals(48, mat.getValue(0, 0, 0), 0); mat = mat.reduce(); - assertEquals(1, mat.getNbDim()); - assertEquals(1, mat.getDim(0)); - assertEquals(48, mat.getValue(0), 0); + Assert.assertEquals(1, mat.getNbDim()); + Assert.assertEquals(1, mat.getDim(0)); + Assert.assertEquals(48, mat.getValue(0), 0); mat = getFactory().create(new int[] { 6, 7, 8 }); MatrixHelper.fill(mat, 3); mat = mat.sumOverDim(1); - assertEquals(21, mat.getValue(0, 0, 0), 0); + Assert.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); + Assert.assertEquals(2, mat.getNbDim()); + Assert.assertEquals(6, mat.getDim(0)); + Assert.assertEquals(8, mat.getDim(1)); + Assert.assertEquals(21, mat.getValue(0, 0), 0); + Assert.assertEquals(21, mat.getValue(5, 7), 0); mat = getFactory().create(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); + Assert.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); + Assert.assertEquals(2, mat.getNbDim()); + Assert.assertEquals(1, mat.getDim(0)); + Assert.assertEquals(2, mat.getDim(1)); + Assert.assertEquals(104, mat.getValue(0, 0), 0); + Assert.assertEquals(104, mat.getValue(0, 1), 0); mat = getFactory().create(new int[] { 2, 2, 2 }); MatrixHelper.fill(mat, 6); @@ -499,46 +514,50 @@ mat = mat.sumOverDim(1); mat = mat.sumOverDim(2); mat = mat.sumOverDim(0); - assertEquals(48, mat.getValue(0, 0, 0), 0); + Assert.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); + Assert.assertEquals(3, mat.getNbDim()); + Assert.assertEquals(1, mat.getDim(0)); + Assert.assertEquals(1, mat.getDim(1)); + Assert.assertEquals(1, mat.getDim(2)); + Assert.assertEquals(48, mat.getValue(0, 0, 0), 0); } - + + @Test public void testCreateFromDoubleArray() throws Exception { - MatrixND mat = null; - - mat = getFactory().create(new double[] {1,2,3,4,5,6,7,8,9}, new int[] {3,3}); - - assertEquals(2,mat.getDim().length); - assertEquals(3,mat.getDim(0)); - assertEquals(3,mat.getDim(1)); - assertEquals(1,(int)mat.getValue(new int[] {0,0})); - assertEquals(2,(int)mat.getValue(new int[] {0,1})); - assertEquals(3,(int)mat.getValue(new int[] {0,2})); - assertEquals(4,(int)mat.getValue(new int[] {1,0})); - assertEquals(5,(int)mat.getValue(new int[] {1,1})); - assertEquals(6,(int)mat.getValue(new int[] {1,2})); - assertEquals(7,(int)mat.getValue(new int[] {2,0})); - assertEquals(8,(int)mat.getValue(new int[] {2,1})); - assertEquals(9,(int)mat.getValue(new int[] {2,2})); - - mat = getFactory().create(new double[] {1,2,3}, new int[]{3}); - assertEquals(1,mat.getDim().length); - assertEquals(3,mat.getDim(0)); - assertEquals(1,(int)mat.getValue(new int[] {0})); - assertEquals(2,(int)mat.getValue(new int[] {1})); - assertEquals(3,(int)mat.getValue(new int[] {2})); - - mat = getFactory().create(new double[] {1,2,3,4,5,6,7,8}, new int[] {2,2,2}); - assertNull(mat); - + MatrixND mat = null; + + mat = getFactory().create(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, + new int[] { 3, 3 }); + + Assert.assertEquals(2, mat.getDim().length); + Assert.assertEquals(3, mat.getDim(0)); + Assert.assertEquals(3, mat.getDim(1)); + Assert.assertEquals(1, (int) mat.getValue(new int[] { 0, 0 })); + Assert.assertEquals(2, (int) mat.getValue(new int[] { 0, 1 })); + Assert.assertEquals(3, (int) mat.getValue(new int[] { 0, 2 })); + Assert.assertEquals(4, (int) mat.getValue(new int[] { 1, 0 })); + Assert.assertEquals(5, (int) mat.getValue(new int[] { 1, 1 })); + Assert.assertEquals(6, (int) mat.getValue(new int[] { 1, 2 })); + Assert.assertEquals(7, (int) mat.getValue(new int[] { 2, 0 })); + Assert.assertEquals(8, (int) mat.getValue(new int[] { 2, 1 })); + Assert.assertEquals(9, (int) mat.getValue(new int[] { 2, 2 })); + + mat = getFactory().create(new double[] { 1, 2, 3 }, new int[] { 3 }); + Assert.assertEquals(1, mat.getDim().length); + Assert.assertEquals(3, mat.getDim(0)); + Assert.assertEquals(1, (int) mat.getValue(new int[] { 0 })); + Assert.assertEquals(2, (int) mat.getValue(new int[] { 1 })); + Assert.assertEquals(3, (int) mat.getValue(new int[] { 2 })); + + mat = getFactory().create(new double[] { 1, 2, 3, 4, 5, 6, 7, 8 }, + new int[] { 2, 2, 2 }); + Assert.assertNull(mat); + } + @Test public void testReduceDims() throws Exception { MatrixND mat = null; @@ -547,25 +566,25 @@ MatrixHelper.fill(mat, 3); mat = mat.sumOverDim(1); - assertEquals(21, mat.getValue(0, 0, 0), 0); + Assert.assertEquals(21, mat.getValue(0, 0, 0), 0); mat = mat.reduceDims(1); - 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); + Assert.assertEquals(2, mat.getNbDim()); + Assert.assertEquals(6, mat.getDim(0)); + Assert.assertEquals(8, mat.getDim(1)); + Assert.assertEquals(21, mat.getValue(0, 0), 0); + Assert.assertEquals(21, mat.getValue(5, 7), 0); mat = getFactory().create(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); + Assert.assertEquals(104, mat.getValue(0, 0, 0), 0); mat = mat.reduceDims(1, 0); - assertEquals(1, mat.getNbDim()); - assertEquals(2, mat.getDim(0)); - assertEquals(104, mat.getValue(0), 0); - assertEquals(104, mat.getValue(1), 0); + Assert.assertEquals(1, mat.getNbDim()); + Assert.assertEquals(2, mat.getDim(0)); + Assert.assertEquals(104, mat.getValue(0), 0); + Assert.assertEquals(104, mat.getValue(1), 0); mat = getFactory().create(new int[] { 2, 2, 2 }); MatrixHelper.fill(mat, 6); @@ -573,37 +592,37 @@ mat = mat.sumOverDim(1); mat = mat.sumOverDim(2); mat = mat.sumOverDim(0); - assertEquals(48, mat.getValue(0, 0, 0), 0); + Assert.assertEquals(48, mat.getValue(0, 0, 0), 0); mat = mat.reduceDims(1, 2, 0); - assertEquals(1, mat.getNbDim()); - assertEquals(1, mat.getDim(0)); - assertEquals(48, mat.getValue(0), 0); + Assert.assertEquals(1, mat.getNbDim()); + Assert.assertEquals(1, mat.getDim(0)); + Assert.assertEquals(48, mat.getValue(0), 0); mat = getFactory().create(new int[] { 6, 7, 8 }); MatrixHelper.fill(mat, 3); mat = mat.sumOverDim(1); - assertEquals(21, mat.getValue(0, 0, 0), 0); + Assert.assertEquals(21, mat.getValue(0, 0, 0), 0); mat = mat.reduceDims(0); - assertEquals(3, mat.getNbDim()); - assertEquals(6, mat.getDim(0)); - assertEquals(1, mat.getDim(1)); - assertEquals(8, mat.getDim(2)); - assertEquals(21, mat.getValue(0, 0, 0), 0); - assertEquals(21, mat.getValue(5, 0, 7), 0); + Assert.assertEquals(3, mat.getNbDim()); + Assert.assertEquals(6, mat.getDim(0)); + Assert.assertEquals(1, mat.getDim(1)); + Assert.assertEquals(8, mat.getDim(2)); + Assert.assertEquals(21, mat.getValue(0, 0, 0), 0); + Assert.assertEquals(21, mat.getValue(5, 0, 7), 0); mat = getFactory().create(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); + Assert.assertEquals(104, mat.getValue(0, 0, 0), 0); mat = mat.reduceDims(1); - 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); + Assert.assertEquals(2, mat.getNbDim()); + Assert.assertEquals(1, mat.getDim(0)); + Assert.assertEquals(2, mat.getDim(1)); + Assert.assertEquals(104, mat.getValue(0, 0), 0); + Assert.assertEquals(104, mat.getValue(0, 1), 0); mat = getFactory().create(new int[] { 2, 2, 2 }); MatrixHelper.fill(mat, 6); @@ -611,14 +630,15 @@ mat = mat.sumOverDim(1); mat = mat.sumOverDim(2); mat = mat.sumOverDim(0); - assertEquals(48, mat.getValue(0, 0, 0), 0); + Assert.assertEquals(48, mat.getValue(0, 0, 0), 0); mat = mat.reduceDims(0, 1, 2); - assertEquals(1, mat.getNbDim()); - assertEquals(1, mat.getDim(0)); - assertEquals(48, mat.getValue(0), 0); + Assert.assertEquals(1, mat.getNbDim()); + Assert.assertEquals(1, mat.getDim(0)); + Assert.assertEquals(48, mat.getValue(0), 0); } + @Test public void testToList() throws Exception { MatrixND mat1 = getFactory().create(new int[] { 3, 2, 1 }); mat1.setValue(0, 0, 0, 1.0E-7); @@ -633,7 +653,7 @@ System.out.println(mat1); System.out.println(mat2); - assertEquals(mat1, mat2); + Assert.assertEquals(mat1, mat2); String s = String.valueOf(l); List l2 = convertStringToList2(s); @@ -645,7 +665,7 @@ System.out.println(l1); System.out.println(l0); // implatation fausse - assertEquals(l, l2); + Assert.assertEquals(l, l2); int MAX = 10000; int dummy = 0; @@ -677,7 +697,7 @@ /** * implantation peut performante */ - static public List convertStringToList1(String s) { + public static List convertStringToList1(String s) { List result = new ArrayList(); s = s.trim(); if (s.startsWith("[") && s.endsWith("]")) { @@ -701,7 +721,7 @@ /** * implantation utilisé actuellement dans MatrixHelper */ - static public List convertStringToList2(String s) { + public static List convertStringToList2(String s) { List result = null; Stack<List> stack = new Stack<List>(); StringBuffer number = new StringBuffer(20); // initial to 20 char @@ -749,7 +769,7 @@ /** * implantation fausse pour les nombres 5.0E-7 */ - static public List convertStringToList0(String s) throws IOException { + public static List convertStringToList0(String s) throws IOException { List result = null; Stack<List> stack = new Stack<List>(); StringBuffer number = new StringBuffer(20); // initial to 20 char Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/PerfTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/PerfTest.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/PerfTest.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,7 +15,15 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * +package org.codelutin.math.matrix; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang.time.DurationFormatUtils; +import org.junit.Test; + +/** * PerfTest.java * * Created: 7 sept. 06 02:28:51 @@ -26,26 +34,12 @@ * Last update: $Date$ * by : $Author$ */ +public class PerfTest { -package org.codelutin.math.matrix; + protected static final char CMAX = 'j'; + protected static final int MAX = 10; -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.commons.lang.time.DurationFormatUtils; - -/** - * @author poussin - * - */ - -public class PerfTest extends TestCase { - - static char CMAX = 'j'; - static int MAX = 10; - + @Test public void testDoubleVectorIterator() throws Exception { List sem = new ArrayList(); for (char c = 'a'; c <= CMAX; c++) { @@ -77,6 +71,7 @@ (timeend - timeinit) / 1000000, "s'.'S")); } + @Test public void testDoubleVectorIndex() throws Exception { List sem = new ArrayList(); for (char c = 'a'; c <= CMAX; c++) { @@ -112,6 +107,7 @@ (timeend - timeinit) / 1000000, "s'.'S")); } + @Test public void testDoubleVectorSemantic() throws Exception { List<String> sem = new ArrayList<String>(); for (char c = 'a'; c <= CMAX; c++) { @@ -150,6 +146,7 @@ (timeend - timeinit) / 1000000, "s'.'S")); } + @Test public void testDoubleBigVectorIterator() throws Exception { List sem = new ArrayList(); for (char c = 'a'; c <= CMAX; c++) { @@ -181,6 +178,7 @@ (timeend - timeinit) / 1000000, "s'.'S")); } + @Test public void testDoubleBigVectorIndex() throws Exception { List sem = new ArrayList(); for (char c = 'a'; c <= CMAX; c++) { @@ -216,6 +214,7 @@ (timeend - timeinit) / 1000000, "s'.'S")); } + @Test public void testDoubleBigVectorSemantic() throws Exception { List<String> sem = new ArrayList<String>(); for (char c = 'a'; c <= CMAX; c++) { @@ -254,6 +253,7 @@ (timeend - timeinit) / 1000000, "s'.'S")); } + @Test public void testFloatVectorIterator() throws Exception { List sem = new ArrayList(); for (char c = 'a'; c <= CMAX; c++) { @@ -285,6 +285,7 @@ (timeend - timeinit) / 1000000, "s'.'S")); } + @Test public void testFloatVectorIndex() throws Exception { List sem = new ArrayList(); for (char c = 'a'; c <= CMAX; c++) { @@ -320,6 +321,7 @@ (timeend - timeinit) / 1000000, "s'.'S")); } + @Test public void testFloatVectorSemantic() throws Exception { List<String> sem = new ArrayList<String>(); for (char c = 'a'; c <= CMAX; c++) { @@ -358,6 +360,7 @@ (timeend - timeinit) / 1000000, "s'.'S")); } + @Test public void testFloatBigVectorIterator() throws Exception { List sem = new ArrayList(); for (char c = 'a'; c <= CMAX; c++) { @@ -389,6 +392,7 @@ (timeend - timeinit) / 1000000, "s'.'S")); } + @Test public void testFloatBigVectorIndex() throws Exception { List sem = new ArrayList(); for (char c = 'a'; c <= CMAX; c++) { @@ -424,6 +428,7 @@ (timeend - timeinit) / 1000000, "s'.'S")); } + @Test public void testFloatBigVectorSemantic() throws Exception { List<String> sem = new ArrayList<String>(); for (char c = 'a'; c <= CMAX; c++) { Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/SubMatrixTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/SubMatrixTest.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/SubMatrixTest.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /*##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -20,25 +20,27 @@ import java.util.Arrays; import java.util.List; -import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Test; /** - * SubMatrixTest.java + * SubMatrixTest. * * Created: 29 oct. 2004 * * @author Benjamin Poussin <poussin@codelutin.com> * @version $Revision$ * - * Mise a jour: $Date$ - * par : $Author$ + * Mise a jour: $Date$ + * par : $Author$ */ -public class SubMatrixTest extends TestCase { // SubMatrixTest +public class SubMatrixTest { // SubMatrixTest public MatrixFactory getFactory() throws Exception { return MatrixFactory.getInstance(); } + @Test public void testNew() throws Exception { List s1 = Arrays.asList(new String[] { "a", "b", "c" }); List s2 = Arrays.asList(new String[] { "e", "f", "g" }); @@ -50,9 +52,10 @@ 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())); + Assert.assertTrue(Arrays.equals(new int[] { 3, 2, 3 }, smat.getDim())); } + @Test public void testIterator() throws Exception { int[][] val18 = new int[][] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 }, { 0, 1, 0 }, { 0, 1, 1 }, { 0, 1, 2 }, { 1, 0, 0 }, @@ -90,13 +93,14 @@ // System.out.println(MatrixHelper.coordinatesToString(i. // getSemanticsCoordinates())); - assertTrue(Arrays.equals(val18[cpt], i.getCoordinates())); - assertTrue(Arrays.equals(vals18[cpt], i.getSemanticsCoordinates())); + Assert.assertTrue(Arrays.equals(val18[cpt], i.getCoordinates())); + Assert.assertTrue(Arrays.equals(vals18[cpt], i.getSemanticsCoordinates())); cpt++; } - assertEquals(18, cpt); + Assert.assertEquals(18, cpt); } + @Test public void testSubSubMatrix() throws Exception { int[][] val6 = new int[][] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 }, { 0, 1, 0 }, { 0, 1, 1 }, { 0, 1, 2 }, }; @@ -119,7 +123,7 @@ //System.out.println(" smat2.getDim: "+MatrixHelper.coordinatesToString( // smat2.getDim())); - assertTrue(Arrays.equals(new int[] { 1, 2, 3 }, smat2.getDim())); + Assert.assertTrue(Arrays.equals(new int[] { 1, 2, 3 }, smat2.getDim())); // System.out.println(MatrixHelper.coordinatesToString(smat2.getDim())); @@ -127,13 +131,14 @@ for (MatrixIterator i = smat2.iterator(); i.hasNext();) { i.next(); - assertTrue(Arrays.equals(val6[cpt], i.getCoordinates())); - assertTrue(Arrays.equals(vals6[cpt], i.getSemanticsCoordinates())); + Assert.assertTrue(Arrays.equals(val6[cpt], i.getCoordinates())); + Assert.assertTrue(Arrays.equals(vals6[cpt], i.getSemanticsCoordinates())); cpt++; } - assertEquals(6, cpt); + Assert.assertEquals(6, cpt); } + @Test public void testSubSubGetSet() throws Exception { List s1 = Arrays.asList(new String[] { "a", "b", "c" }); List s2 = Arrays.asList(new String[] { "e", "f", "g" }); @@ -148,11 +153,12 @@ MatrixND smat2 = smat1.getSubMatrix(0, 2, 1); smat2.setValue(0, 0, 0, 34); - assertEquals(34, smat2.getValue("c", "e", "k"), 0); + Assert.assertEquals(34, smat2.getValue("c", "e", "k"), 0); smat2.setValue("c", "f", "l", 23); - assertEquals(23, smat2.getValue(0, 1, 1), 0); + Assert.assertEquals(23, smat2.getValue(0, 1, 1), 0); } + @Test public void testSubMapping() throws Exception { List s1 = Arrays.asList(new String[] { "a", "b", "c" }); List s2 = Arrays.asList(new String[] { "e", "f", "g" }); @@ -164,29 +170,30 @@ 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 + Assert.assertEquals(2, smat1.getDim(1)); + Assert.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)); + Assert.assertEquals(1, smat2.getDim(0)); + Assert.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); + Assert.assertEquals(12, smat1.getValue(2, 1, 0), 0); + Assert.assertEquals(12, smat1.getValue("c", "f", "k"), 0); + Assert.assertEquals(12, smat2.getValue(0, 1, 0), 0); + Assert.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); + Assert.assertEquals(34, smat2.getValue("c", "e", "k"), 0); + Assert.assertEquals(34, mat.getValue(2, 0, 0), 0); + Assert.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); + Assert.assertEquals(23, smat2.getValue(0, 1, 1), 0); + Assert.assertEquals(23, mat.getValue(2, 1, 1), 0); + Assert.assertEquals(23, mat.getValue("c", "f", "l"), 0); } + @Test public void testSubAdd() throws Exception { List s1 = Arrays.asList(new String[] { "a", "b", "c" }); List s2 = Arrays.asList(new String[] { "e", "f", "g" }); @@ -208,37 +215,38 @@ smat1.add(smat2); - assertEquals(5, mat1.getValue(0, 1, 0), 0); - assertEquals(5, mat1.getValue(0, 1, 1), 0); - assertEquals(5, mat1.getValue(0, 1, 2), 0); - assertEquals(5, mat1.getValue(1, 1, 0), 0); - assertEquals(5, mat1.getValue(1, 1, 1), 0); - assertEquals(5, mat1.getValue(1, 1, 2), 0); - assertEquals(5, mat1.getValue(2, 1, 0), 0); - assertEquals(5, mat1.getValue(2, 1, 1), 0); - assertEquals(5, mat1.getValue(2, 1, 2), 0); - assertEquals(5, mat1.getValue(0, 2, 0), 0); - assertEquals(5, mat1.getValue(0, 2, 1), 0); - assertEquals(5, mat1.getValue(0, 2, 2), 0); - assertEquals(5, mat1.getValue(1, 2, 0), 0); - assertEquals(5, mat1.getValue(1, 2, 1), 0); - assertEquals(5, mat1.getValue(1, 2, 2), 0); - assertEquals(5, mat1.getValue(2, 2, 0), 0); - assertEquals(5, mat1.getValue(2, 2, 1), 0); - assertEquals(5, mat1.getValue(2, 2, 2), 0); + Assert.assertEquals(5, mat1.getValue(0, 1, 0), 0); + Assert.assertEquals(5, mat1.getValue(0, 1, 1), 0); + Assert.assertEquals(5, mat1.getValue(0, 1, 2), 0); + Assert.assertEquals(5, mat1.getValue(1, 1, 0), 0); + Assert.assertEquals(5, mat1.getValue(1, 1, 1), 0); + Assert.assertEquals(5, mat1.getValue(1, 1, 2), 0); + Assert.assertEquals(5, mat1.getValue(2, 1, 0), 0); + Assert.assertEquals(5, mat1.getValue(2, 1, 1), 0); + Assert.assertEquals(5, mat1.getValue(2, 1, 2), 0); + Assert.assertEquals(5, mat1.getValue(0, 2, 0), 0); + Assert.assertEquals(5, mat1.getValue(0, 2, 1), 0); + Assert.assertEquals(5, mat1.getValue(0, 2, 2), 0); + Assert.assertEquals(5, mat1.getValue(1, 2, 0), 0); + Assert.assertEquals(5, mat1.getValue(1, 2, 1), 0); + Assert.assertEquals(5, mat1.getValue(1, 2, 2), 0); + Assert.assertEquals(5, mat1.getValue(2, 2, 0), 0); + Assert.assertEquals(5, mat1.getValue(2, 2, 1), 0); + Assert.assertEquals(5, mat1.getValue(2, 2, 2), 0); - assertEquals(8, mat1.getValue(0, 0, 0), 0); - assertEquals(8, mat1.getValue(0, 0, 1), 0); - assertEquals(8, mat1.getValue(0, 0, 2), 0); - assertEquals(8, mat1.getValue(1, 0, 0), 0); - assertEquals(8, mat1.getValue(1, 0, 1), 0); - assertEquals(8, mat1.getValue(1, 0, 2), 0); - assertEquals(8, mat1.getValue(2, 0, 0), 0); - assertEquals(8, mat1.getValue(2, 0, 1), 0); - assertEquals(8, mat1.getValue(2, 0, 2), 0); + Assert.assertEquals(8, mat1.getValue(0, 0, 0), 0); + Assert.assertEquals(8, mat1.getValue(0, 0, 1), 0); + Assert.assertEquals(8, mat1.getValue(0, 0, 2), 0); + Assert.assertEquals(8, mat1.getValue(1, 0, 0), 0); + Assert.assertEquals(8, mat1.getValue(1, 0, 1), 0); + Assert.assertEquals(8, mat1.getValue(1, 0, 2), 0); + Assert.assertEquals(8, mat1.getValue(2, 0, 0), 0); + Assert.assertEquals(8, mat1.getValue(2, 0, 1), 0); + Assert.assertEquals(8, mat1.getValue(2, 0, 2), 0); } + @Test public void testSubSubMults() throws Exception { MatrixND mat = null; Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/gui/MatrixTableModelTest.java =================================================================== --- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/gui/MatrixTableModelTest.java 2009-03-03 09:07:38 UTC (rev 119) +++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/gui/MatrixTableModelTest.java 2009-03-03 10:19:18 UTC (rev 120) @@ -1,5 +1,5 @@ /* *##% lutinmatrix - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -15,42 +15,38 @@ * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ -/* * - * MatrixTableModelND.java - * - * Created: 21 mars 2006 19:05:06 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - package org.codelutin.math.matrix.gui; import java.util.Arrays; import java.util.List; -import junit.framework.TestCase; - import org.codelutin.math.matrix.MatrixFactory; import org.codelutin.math.matrix.MatrixND; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; /** + * MatrixTableModelND. + * + * Created: 21 mars 2006 19:05:06 + * * @author poussin - * + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ */ +public class MatrixTableModelTest { -public class MatrixTableModelTest extends TestCase { + protected MatrixTableModelND model = null; + protected MatrixND mat = null; - MatrixTableModelND model = null; - MatrixND mat = null; - /* * @see TestCase#setUp() */ - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { List dim0 = Arrays.asList(new String[] { "dim0-0", "dim0-1", "dim0-2", "dim0-3" }); List dim1 = Arrays.asList(new String[] { "dim1-0", "dim1-1" }); @@ -65,70 +61,76 @@ model = new MatrixTableModelND(mat); } + @Test public void testSetMatrix() { - assertEquals(2, model.addRow); - assertEquals(3, model.addCol); + Assert.assertEquals(2, model.addRow); + Assert.assertEquals(3, model.addCol); int[] val = model.multRowCol; - assertEquals(true, Arrays.equals(new int[] { 6, 4, 3, 1, 1 }, val)); + Assert.assertEquals(true, Arrays.equals(new int[] { 6, 4, 3, 1, 1 }, + val)); } /* - * Test method for - * 'org.codelutin.math.matrix.gui.MatrixTableModelND.isCellEditable(int, - * int)' + * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.isCellEditable(int, int)' */ + @Test public void testIsCellEditable() { - assertEquals(false, model.isCellEditable(model.addRow - 1, + Assert.assertEquals(false, model.isCellEditable(model.addRow - 1, model.addCol - 1)); - assertEquals(true, model.isCellEditable(model.addRow, model.addCol)); - assertEquals(true, model.isCellEditable(model.addRow + 1, + Assert.assertEquals(true, model.isCellEditable(model.addRow, + model.addCol)); + Assert.assertEquals(true, model.isCellEditable(model.addRow + 1, model.addCol + 1)); } /* - * Test method for - * 'org.codelutin.math.matrix.gui.MatrixTableModelND.tableToMatrix(int, - * int)' + * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.tableToMatrix(int, int)' */ + @Test public void testTableToMatrix() { int[] val = model.tableToMatrix(5, 4); - assertEquals(true, Arrays.equals(new int[] { 0, 1, 1, 0, 2 }, val)); + Assert.assertEquals(true, Arrays.equals(new int[] { 0, 1, 1, 0, 2 }, + val)); val = model.tableToMatrix(0, 0); - assertEquals(true, Arrays.equals(new int[] { 0, 0, 0, 0, 0 }, val)); + Assert.assertEquals(true, Arrays.equals(new int[] { 0, 0, 0, 0, 0 }, + val)); val = model.tableToMatrix(23, 5); - assertEquals(true, Arrays.equals(new int[] { 3, 1, 1, 1, 2 }, val)); + Assert.assertEquals(true, Arrays.equals(new int[] { 3, 1, 1, 1, 2 }, + val)); } /* - * Test method for - * 'org.codelutin.math.matrix.gui.MatrixTableModelND.getValue(int, int)' + * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.getValue(int, int)' */ + @Test public void testGetValue() { - assertEquals("dim0-0", model.getValue(2, 0)); - assertEquals("dim0-0", model.getValue(3, 0)); - assertEquals("dim0-0", model.getValue(4, 0)); - assertEquals("dim0-0", model.getValue(7, 0)); - assertEquals("dim0-1", model.getValue(8, 0)); + Assert.assertEquals("dim0-0", model.getValue(2, 0)); + Assert.assertEquals("dim0-0", model.getValue(3, 0)); + Assert.assertEquals("dim0-0", model.getValue(4, 0)); + Assert.assertEquals("dim0-0", model.getValue(7, 0)); + Assert.assertEquals("dim0-1", model.getValue(8, 0)); - assertEquals("dim2-0", model.getValue(2, 1)); - assertEquals("dim2-0", model.getValue(3, 1)); - assertEquals("dim2-1", model.getValue(5, 1)); + Assert.assertEquals("dim2-0", model.getValue(2, 1)); + Assert.assertEquals("dim2-0", model.getValue(3, 1)); + Assert.assertEquals("dim2-1", model.getValue(5, 1)); - assertEquals("dim4-0", model.getValue(2, 2)); - assertEquals("dim4-1", model.getValue(3, 2)); - assertEquals("dim4-2", model.getValue(4, 2)); - assertEquals("dim4-0", model.getValue(5, 2)); + Assert.assertEquals("dim4-0", model.getValue(2, 2)); + Assert.assertEquals("dim4-1", model.getValue(3, 2)); + Assert.assertEquals("dim4-2", model.getValue(4, 2)); + Assert.assertEquals("dim4-0", model.getValue(5, 2)); - assertEquals("dim1-0", model.getValue(0, 3)); + Assert.assertEquals("dim1-0", model.getValue(0, 3)); - assertEquals(0.0, model.getValue(model.addRow, model.addCol)); - assertEquals(0.0, model.getValue(23 + model.addRow, 5 + model.addCol)); + Assert.assertEquals(0.0, model.getValue(model.addRow, model.addCol)); + Assert.assertEquals(0.0, model.getValue(23 + model.addRow, + 5 + model.addCol)); } /* * Test method for * 'org.codelutin.math.matrix.gui.MatrixTableModelND.getColumnName(int)' */ + @Test public void testGetColumnNameInt() { } @@ -137,6 +139,7 @@ * Test method for * 'org.codelutin.math.matrix.gui.MatrixTableModelND.getRowCount()' */ + @Test public void testGetRowCount() { } @@ -145,6 +148,7 @@ * Test method for * 'org.codelutin.math.matrix.gui.MatrixTableModelND.getColumnCount()' */ + @Test public void testGetColumnCount() { } @@ -153,6 +157,7 @@ * Test method for * 'org.codelutin.math.matrix.gui.MatrixTableModelND.getValueAt(int, int)' */ + @Test public void testGetValueAt() { } @@ -162,6 +167,7 @@ * 'org.codelutin.math.matrix.gui.MatrixTableModelND.setValueAt(Object, int, * int)' */ + @Test public void testSetValueAtObjectIntInt() { } Added: lutinmatrix/trunk/src/test/resources/log4j.properties =================================================================== --- lutinmatrix/trunk/src/test/resources/log4j.properties (rev 0) +++ lutinmatrix/trunk/src/test/resources/log4j.properties 2009-03-03 10:19:18 UTC (rev 120) @@ -0,0 +1,10 @@ +# Global logging configuration +log4j.rootLogger=ERROR, stdout + +# Console output... +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n + +# package level +log4j.logger.org.codelutin.math=DEBUG \ No newline at end of file