aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/tests/OutputTests.java
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-02-12 11:57:18 +0000
committerEduardo Pedroni <ep625@york.ac.uk>2014-02-12 11:57:18 +0000
commit727801ab8002481fd2d213b45c3b43225b0f73bb (patch)
tree88f30ff057cb433f4a83a2e2acd4b5391c8935e7 /src/jcgp/tests/OutputTests.java
parentccdecd80ffe482fbe994515e98eeae68fb4ca401 (diff)
Added a few more tests, be back after the meeting.
Diffstat (limited to 'src/jcgp/tests/OutputTests.java')
-rw-r--r--src/jcgp/tests/OutputTests.java108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/jcgp/tests/OutputTests.java b/src/jcgp/tests/OutputTests.java
new file mode 100644
index 0000000..06295ae
--- /dev/null
+++ b/src/jcgp/tests/OutputTests.java
@@ -0,0 +1,108 @@
+package jcgp.tests;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Random;
+
+import jcgp.Parameters;
+import jcgp.Utilities;
+import jcgp.population.Chromosome;
+import jcgp.population.Connection;
+import jcgp.population.Output;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ * Tests which cover the behaviour specified for an output.
+ *
+ * - An output contains a single source Connection, which can be set and got.
+ * - It should return the value of its source connection.
+ * - It must be addressable by an index set upon construction only.
+ *
+ *
+ * @author Eduardo Pedroni
+ *
+ */
+public class OutputTests {
+
+ private Output output;
+ private static Chromosome chromosome;
+ // these are the test values
+ private final int outputValue = 10;
+ private final int outputIndex = 2;
+
+ @BeforeClass
+ public static void setUpBeforeClass() {
+ // initialise utilities
+ Utilities.setResources(new Random(1234), null);
+
+ // initialise parameters
+ Parameters.setColumns(0);
+ Parameters.setRows(0);
+ Parameters.setInputs(0);
+ Parameters.setOutputs(0);
+ Parameters.setLevelsBack(0);
+ Parameters.setMutationRate(10);
+ Parameters.setTotalGenerations(100);
+ Parameters.setTotalRuns(5);
+ Parameters.setMaxArity(2);
+
+ chromosome = new Chromosome();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ output = new Output(chromosome, outputIndex);
+ }
+
+ @Test
+ public void evaluationsTest() {
+ // set source connection, check that the appropriate value is returned
+ output.setConnection(new Connection() {
+
+ @Override
+ public int getValue() {
+ // test value
+ return outputValue;
+ }
+
+ @Override
+ public void getActive(ArrayList<Connection> activeNodes) {
+ // blank
+ }
+ });
+
+ assertTrue("Incorrect evaluation.", output.calculate() == outputValue);
+ }
+
+ @Test
+ public void connectionTest() {
+ // set a new connection, check that it is correctly returned
+ Connection newConn = new Connection() {
+
+ @Override
+ public int getValue() {
+ // blank
+ return 0;
+ }
+
+ @Override
+ public void getActive(ArrayList<Connection> activeNodes) {
+ // blank
+ }
+ };
+ output.setConnection(newConn);
+
+ assertTrue("Incorrect connection returned.", output.getSource() == newConn);
+ }
+
+ @Test
+ public void indexTest() {
+ // check that the index returned is the one passed to the constructor
+ assertTrue("Incorrect index returned.", output.getIndex() == outputIndex);
+ }
+}