Author: chatellier Date: 2009-02-24 10:33:31 +0000 (Tue, 24 Feb 2009) New Revision: 1865 Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/factors/FactorTest.java Log: Update factors tests Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/factors/FactorTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/factors/FactorTest.java 2009-02-24 09:59:44 UTC (rev 1864) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/factors/FactorTest.java 2009-02-24 10:33:31 UTC (rev 1865) @@ -22,9 +22,9 @@ import org.apache.commons.logging.LogFactory; import org.codelutin.math.matrix.MatrixFactory; import org.codelutin.math.matrix.MatrixND; +import org.junit.Assert; import org.junit.Test; - /** * Factors test. * @@ -38,27 +38,28 @@ /** to use log facility, just put in your code: log.info(\"...\"); */ private static Log log = LogFactory.getLog(FactorTest.class); - + /** * Test to build new factors with int values. */ @Test public void testIntFactor() { - + Factor<Integer> factor = new Factor<Integer>("testint"); - factor.getDomain().put("i1", 0); - factor.getDomain().put("i2", 1); - factor.getDomain().put("i3", 2); - factor.getDomain().put("i4", 3); - factor.getDomain().put("i5", 4); + ContinuousDomain<Integer> domain = new ContinuousDomain<Integer>(); + domain.setMinBound(0); + domain.setMaxBound(50); + factor.setDomain(domain); factor.setPath("org.codelutin.factor#1234567890#0.12242345354#name"); - factor.setValueLabel("i3"); - + factor.setValueForIdentifier(49); + + Assert.assertEquals((Integer) 49, factor.getValue()); + if (log.isInfoEnabled()) { log.info("factor#toString() = " + factor); } } - + /** * Test factor with matrix. * @@ -66,32 +67,47 @@ */ @Test public void testMatrixFactor() { - + // matrix 1 - MatrixND matrix1 = MatrixFactory.getInstance().create("test1", new int[] {3,2}, new String[]{"col1", "col2"}); - matrix1.setValue(new int[]{0,0}, 13); - matrix1.setValue(new int[]{0,1}, -14); - matrix1.setValue(new int[]{1,0}, 21); - matrix1.setValue(new int[]{1,1}, 2); - matrix1.setValue(new int[]{2,0}, 12); - matrix1.setValue(new int[]{2,1}, -1); - + MatrixND matrix1 = MatrixFactory.getInstance().create("test1", + new int[] { 3, 2 }, new String[] { "col1", "col2" }); + matrix1.setValue(new int[] { 0, 0 }, 13); + matrix1.setValue(new int[] { 0, 1 }, -14); + matrix1.setValue(new int[] { 1, 0 }, 21); + matrix1.setValue(new int[] { 1, 1 }, 2); + matrix1.setValue(new int[] { 2, 0 }, 12); + matrix1.setValue(new int[] { 2, 1 }, -1); + // matrix 2 - MatrixND matrix2 = MatrixFactory.getInstance().create("test2", new int[] {2,3}, new String[]{"col1", "col2"}); - matrix2.setValue(new int[]{0,0}, 9999); - matrix2.setValue(new int[]{0,1}, 15000); - matrix2.setValue(new int[]{0,2}, -40000); - matrix2.setValue(new int[]{1,0}, 21345); - matrix2.setValue(new int[]{1,1}, 81000); - matrix2.setValue(new int[]{1,2}, -13000); - + MatrixND matrix2 = MatrixFactory.getInstance().create("test2", + new int[] { 2, 3 }, new String[] { "col1", "col2" }); + matrix2.setValue(new int[] { 0, 0 }, 9999); + matrix2.setValue(new int[] { 0, 1 }, 15000); + matrix2.setValue(new int[] { 0, 2 }, -40000); + matrix2.setValue(new int[] { 1, 0 }, 21345); + matrix2.setValue(new int[] { 1, 1 }, 81000); + matrix2.setValue(new int[] { 1, 2 }, -13000); + // factor Factor<MatrixND> factor = new Factor<MatrixND>("testmatrix"); - factor.getDomain().put("m1", matrix1); - factor.getDomain().put("m2", matrix2); + DiscreteDomain<MatrixND> domain = new DiscreteDomain<MatrixND>(); + domain.getValues().put("m1", matrix1); + domain.getValues().put("m2", matrix2); + factor.setDomain(domain); factor.setPath("org.codelutin.math.matrix.MatrixND#563456293453#2.456347646#dim"); - factor.setValueLabel("m2"); - + factor.setValueForIdentifier("m2"); + + Assert.assertEquals(matrix2, factor.getValue()); + + try { + factor.setValueForIdentifier("blah blah"); + Assert.fail("Can't set identifier not present in domain"); + } catch (IllegalArgumentException e) { + if (log.isInfoEnabled()) { + log.info("Exception normally thrown"); + } + } + if (log.isInfoEnabled()) { log.info("factor#toString() = " + factor); }
participants (1)
-
chatellierï¼ users.labs.libre-entreprise.org