From ef7a850a8f2f81ccaa07f25d9b7ad602e84d88c9 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Sun, 16 Feb 2014 22:41:46 +0000 Subject: Light refactoring, a good amount of testing done, added some new functions. --- src/jcgp/tests/ChromosomeTests.java | 5 ++--- src/jcgp/tests/NodeTests.java | 37 +++++++++++++++++++++++++++++++++---- src/jcgp/tests/OutputTests.java | 12 ++++++++++++ src/jcgp/tests/PopulationTests.java | 5 ++--- 4 files changed, 49 insertions(+), 10 deletions(-) (limited to 'src/jcgp/tests') diff --git a/src/jcgp/tests/ChromosomeTests.java b/src/jcgp/tests/ChromosomeTests.java index c943da8..46463c5 100644 --- a/src/jcgp/tests/ChromosomeTests.java +++ b/src/jcgp/tests/ChromosomeTests.java @@ -6,9 +6,8 @@ import java.util.Random; import jcgp.Parameters; import jcgp.Utilities; -import jcgp.function.Addition; +import jcgp.function.Arithmetic; import jcgp.function.FunctionSet; -import jcgp.function.Subtraction; import jcgp.population.Chromosome; import jcgp.population.Connection; import jcgp.population.Input; @@ -50,7 +49,7 @@ public class ChromosomeTests { @BeforeClass public static void setUpBeforeClass() { // initialise function set - FunctionSet functionSet = new FunctionSet(new Addition(), new Subtraction()); + FunctionSet functionSet = new FunctionSet(new Arithmetic.Addition(), new Arithmetic.Subtraction()); // initialise utilities Utilities.setResources(new Random(1234), functionSet); diff --git a/src/jcgp/tests/NodeTests.java b/src/jcgp/tests/NodeTests.java index 9ea6769..ee26d38 100644 --- a/src/jcgp/tests/NodeTests.java +++ b/src/jcgp/tests/NodeTests.java @@ -6,9 +6,8 @@ import java.util.Random; import jcgp.Parameters; import jcgp.Utilities; -import jcgp.function.Addition; +import jcgp.function.Arithmetic; import jcgp.function.Function; -import jcgp.function.Subtraction; import jcgp.population.Chromosome; import jcgp.population.Connection; import jcgp.population.Node; @@ -63,7 +62,7 @@ public class NodeTests { public void setUp() throws Exception { node = new Node(chromosome, 0, 0); // make node with anonymous addition function and hard-coded value connections - node.initialise(new Addition(), + node.initialise(new Arithmetic.Addition(), new Connection[]{new Connection() { @Override @@ -72,6 +71,12 @@ public class NodeTests { return arg1; } + @Override + public String getDescription() { + // blank + return null; + } + }, new Connection() { @@ -81,6 +86,12 @@ public class NodeTests { return arg2; } + @Override + public String getDescription() { + // blank + return null; + } + }}); } @@ -123,7 +134,7 @@ public class NodeTests { ((int) node.getValue()) == arg1 + arg2); // put in a different function, check the output has changed appropriately - node.setFunction(new Subtraction()); + node.setFunction(new Arithmetic.Subtraction()); assertTrue("Node did not return expected value (difference of arguments).", ((Integer) node.getValue()) == arg1 - arg2); @@ -141,6 +152,12 @@ public class NodeTests { return 0; } + @Override + public String getDescription() { + // blank + return null; + } + }; conn1 = new Connection() { @@ -150,6 +167,12 @@ public class NodeTests { return 0; } + @Override + public String getDescription() { + // blank + return null; + } + }; node.initialise(null, conn0, conn1); @@ -164,6 +187,12 @@ public class NodeTests { // blank return 0; } + + @Override + public String getDescription() { + // blank + return null; + } }; node.setConnection(conn2); diff --git a/src/jcgp/tests/OutputTests.java b/src/jcgp/tests/OutputTests.java index c877c03..20e1c7f 100644 --- a/src/jcgp/tests/OutputTests.java +++ b/src/jcgp/tests/OutputTests.java @@ -68,6 +68,12 @@ public class OutputTests { // test value return outputValue; } + + @Override + public String getDescription() { + // blank + return null; + } }); assertTrue("Incorrect evaluation.", ((Integer) output.calculate()) == outputValue); @@ -83,6 +89,12 @@ public class OutputTests { // blank return 0; } + + @Override + public String getDescription() { + // blank + return null; + } }; output.setConnection(newConn); diff --git a/src/jcgp/tests/PopulationTests.java b/src/jcgp/tests/PopulationTests.java index b8639bf..a6ab141 100644 --- a/src/jcgp/tests/PopulationTests.java +++ b/src/jcgp/tests/PopulationTests.java @@ -6,9 +6,8 @@ import java.util.Random; import jcgp.Parameters; import jcgp.Utilities; -import jcgp.function.Addition; +import jcgp.function.Arithmetic; import jcgp.function.FunctionSet; -import jcgp.function.Subtraction; import jcgp.population.Chromosome; import jcgp.population.Population; @@ -39,7 +38,7 @@ public class PopulationTests { @BeforeClass public static void setUpBeforeClass() throws Exception { // initialise function set - FunctionSet functionSet = new FunctionSet(new Addition(), new Subtraction()); + FunctionSet functionSet = new FunctionSet(new Arithmetic.Addition(), new Arithmetic.Subtraction()); // initialise utilities Utilities.setResources(new Random(1234), functionSet); -- cgit v1.2.3