aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/tests/ChromosomeTests.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/tests/ChromosomeTests.java')
-rw-r--r--src/jcgp/tests/ChromosomeTests.java55
1 files changed, 48 insertions, 7 deletions
diff --git a/src/jcgp/tests/ChromosomeTests.java b/src/jcgp/tests/ChromosomeTests.java
index cb2cb95..ff1de18 100644
--- a/src/jcgp/tests/ChromosomeTests.java
+++ b/src/jcgp/tests/ChromosomeTests.java
@@ -57,7 +57,7 @@ public class ChromosomeTests {
Utilities.setResources(new Random(1234), functionSet);
// initialise parameters
- Parameters.setColumns(1);
+ Parameters.setColumns(30);
Parameters.setRows(20);
Parameters.setInputs(2);
Parameters.setOutputs(4);
@@ -90,13 +90,54 @@ public class ChromosomeTests {
chromosome.setInputs(testInputs);
clone.setInputs(testInputs);
- // connect outputs to inputs, check that the outputs match
- for (int i = 0; i < Parameters.getOutputs(); i++) {
- chromosome.getOutput(i).setConnection(chromosome.getInput(i % Parameters.getInputs()));
- clone.getOutput(i).setConnection(clone.getInput(i % Parameters.getInputs()));
- assertTrue("Incorrect output returned.", chromosome.getOutput(i).calculate() ==
- clone.getOutput(i).calculate());
+ // compare all elements, one by one
+ // check outputs
+ for (int o = 0; o < Parameters.getOutputs(); o++) {
+ // check that no cross-references exist between chromosomes
+ assertTrue("Cloned chromosome contained a reference to a member of the original chromosome.",
+ c.getOutput(o) != oc.getOutput(o) &&
+ c.getOutput(o).getSource() != oc.getOutput(o).getSource());
+ // check that the connections are equivalent
+ if (c.getOutput(o).getSource() instanceof Input && oc.getOutput(o).getSource() instanceof Input) {
+ assertTrue("Outputs did not connect to equivalent inputs.",
+ ((Input) c.getOutput(o).getSource()).getIndex() == ((Input) oc.getOutput(o).getSource()).getIndex());
+ } else if (c.getOutput(o).getSource() instanceof Node && oc.getOutput(o).getSource() instanceof Node) {
+ assertTrue("Outputs did not connect to equivalent nodes.",
+ ((Node) c.getOutput(o).getSource()).getRow() == ((Node) oc.getOutput(o).getSource()).getRow() &&
+ ((Node) c.getOutput(o).getSource()).getColumn() == ((Node) oc.getOutput(o).getSource()).getColumn());
+ } else {
+ fail("Output source types did not match.");
+ }
}
+ // check nodes, rows first
+ for (int row = 0; row < Parameters.getRows(); row++) {
+ for (int column = 0; column < Parameters.getColumns(); column++) {
+ // look at each connection
+ for (int connection = 0; connection < Parameters.getMaxArity(); connection++) {
+ if (c.getNode(row, column).getConnection(connection) instanceof Input &&
+ oc.getNode(row, column).getConnection(connection) instanceof Input) {
+
+ assertTrue("Nodes did not connect to equivalent inputs.",
+ ((Input) c.getNode(row, column).getConnection(connection)).getIndex() ==
+ ((Input) oc.getNode(row, column).getConnection(connection)).getIndex());
+
+ } else if (c.getNode(row, column).getConnection(connection) instanceof Node &&
+ oc.getNode(row, column).getConnection(connection) instanceof Node) {
+
+ assertTrue("Nodes did not connect to equivalent nodes.",
+ ((Node) c.getNode(row, column).getConnection(connection)).getRow() ==
+ ((Node) oc.getNode(row, column).getConnection(connection)).getRow() &&
+
+ ((Node) c.getNode(row, column).getConnection(connection)).getColumn() ==
+ ((Node) oc.getNode(row, column).getConnection(connection)).getColumn());
+
+ } else {
+ fail("Connection types did not match.");
+ }
+ }
+ }
+ }
+
// change clone inputs, outputs should no longer match
testInputs = new int[Parameters.getInputs()];