aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/tests
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-04-26 19:56:24 +0100
committerEduardo Pedroni <ep625@york.ac.uk>2014-04-26 19:56:24 +0100
commit4c8de2402f2878cde7587c7f3bbf4ffaea86efd4 (patch)
tree29156510f648a2d9f8de4df3b2617d4a056e1d90 /src/jcgp/backend/tests
parentb0c0698e5503c2506217117bf144fde31e6f6601 (diff)
Moved files around to different folders, and commented some more packages. Aiming to have the entire backend fully commented by the end of today
Diffstat (limited to 'src/jcgp/backend/tests')
-rw-r--r--src/jcgp/backend/tests/ChromosomeTests.java10
-rw-r--r--src/jcgp/backend/tests/NodeTests.java13
-rw-r--r--src/jcgp/backend/tests/TestFunctionSet.java54
3 files changed, 65 insertions, 12 deletions
diff --git a/src/jcgp/backend/tests/ChromosomeTests.java b/src/jcgp/backend/tests/ChromosomeTests.java
index bc0c57d..c326805 100644
--- a/src/jcgp/backend/tests/ChromosomeTests.java
+++ b/src/jcgp/backend/tests/ChromosomeTests.java
@@ -2,7 +2,6 @@ package jcgp.backend.tests;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import jcgp.backend.function.SymbolicRegressionFunctions;
import jcgp.backend.population.Chromosome;
import jcgp.backend.population.Connection;
import jcgp.backend.population.Input;
@@ -46,7 +45,7 @@ public class ChromosomeTests {
@BeforeClass
public static void setUpBeforeClass() {
resources = new ModifiableResources();
- resources.setFunctionSet(new SymbolicRegressionFunctions());
+ resources.setFunctionSet(new TestFunctionSet());
}
@Before
@@ -225,9 +224,12 @@ public class ChromosomeTests {
chromosome.setInputs(5, 8, 4);
+ Integer output0 = (Integer) chromosome.getOutput(0).calculate();
+ Integer output1 = (Integer) chromosome.getOutput(1).calculate();
+
// with this configuration, the outputs should be 13 and 25.
- assertTrue("Incorrect output returned.", (Integer) chromosome.getOutput(0).calculate() == 13);
- assertTrue("Incorrect output returned.", (Integer) chromosome.getOutput(1).calculate() == 25);
+ assertTrue("Incorrect output returned: " + output0, output0 == 13.0);
+ assertTrue("Incorrect output returned: " + output1, output1 == 25.0);
}
/**
diff --git a/src/jcgp/backend/tests/NodeTests.java b/src/jcgp/backend/tests/NodeTests.java
index c63b41e..ee940a0 100644
--- a/src/jcgp/backend/tests/NodeTests.java
+++ b/src/jcgp/backend/tests/NodeTests.java
@@ -1,8 +1,6 @@
package jcgp.backend.tests;
import static org.junit.Assert.assertTrue;
-import jcgp.backend.exceptions.InvalidArgumentsException;
-import jcgp.backend.function.SymbolicRegressionFunctions;
import jcgp.backend.function.Function;
import jcgp.backend.population.Chromosome;
import jcgp.backend.population.Connection;
@@ -41,15 +39,15 @@ public class NodeTests {
public static void setUpBeforeClass() {
resources = new ModifiableResources();
- resources.setFunctionSet(new SymbolicRegressionFunctions());
+ resources.setFunctionSet(new TestFunctionSet());
chromosome = new Chromosome(resources);
}
@Before
public void setUp() throws Exception {
node = new Node(chromosome, 0, 0, resources.arity());
- // make node with anonymous addition function and hard-coded value connections
- node.initialise(new SymbolicRegressionFunctions.Addition(),
+ // make node with addition function and hard-coded value connections
+ node.initialise(resources.getFunction(0),
new Connection[]{new Connection() {
@Override
@@ -107,7 +105,7 @@ public class NodeTests {
((int) node.getValue()) == arg1 + arg2);
// put in a different function, check the output has changed appropriately
- node.setFunction(new SymbolicRegressionFunctions.Subtraction());
+ node.setFunction(resources.getFunction(1));
assertTrue("Node did not return expected value (difference of arguments).", ((Integer) node.getValue()) == arg1 - arg2);
@@ -136,8 +134,7 @@ public class NodeTests {
Function function = new Function() {
@Override
- public Object run(Object... connections)
- throws InvalidArgumentsException {
+ public Object run(Object... connections) {
// blank
return null;
}
diff --git a/src/jcgp/backend/tests/TestFunctionSet.java b/src/jcgp/backend/tests/TestFunctionSet.java
new file mode 100644
index 0000000..1910d2a
--- /dev/null
+++ b/src/jcgp/backend/tests/TestFunctionSet.java
@@ -0,0 +1,54 @@
+package jcgp.backend.tests;
+
+import jcgp.backend.function.Function;
+import jcgp.backend.function.FunctionSet;
+
+public class TestFunctionSet extends FunctionSet {
+
+ public TestFunctionSet() {
+
+ functionList = new Function[] {
+ new Function() {
+ @Override
+ public Object run(Object... args) {
+ return (Integer) args[0] + (Integer) args[1];
+ }
+ @Override
+ public int getArity() {
+ return 2;
+ }
+ },
+ new Function() {
+ @Override
+ public Object run(Object... args) {
+ return (Integer) args[0] - (Integer) args[1];
+ }
+ @Override
+ public int getArity() {
+ return 2;
+ }
+ },
+ new Function() {
+ @Override
+ public Object run(Object... args) {
+ return (Integer) args[0] * (Integer) args[1];
+ }
+ @Override
+ public int getArity() {
+ return 2;
+ }
+ },
+ new Function() {
+ @Override
+ public Object run(Object... args) {
+ return (Integer) args[0] / (Integer) args[1];
+ }
+ @Override
+ public int getArity() {
+ return 2;
+ }
+ }
+ };
+ enableAll();
+ }
+} \ No newline at end of file