aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/function
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/function
parentccdecd80ffe482fbe994515e98eeae68fb4ca401 (diff)
Added a few more tests, be back after the meeting.
Diffstat (limited to 'src/jcgp/function')
-rw-r--r--src/jcgp/function/Addition.java2
-rw-r--r--src/jcgp/function/Function.java3
-rw-r--r--src/jcgp/function/InsufficientArgumentsException.java10
-rw-r--r--src/jcgp/function/Subtraction.java2
4 files changed, 14 insertions, 3 deletions
diff --git a/src/jcgp/function/Addition.java b/src/jcgp/function/Addition.java
index faf11d5..45a8d35 100644
--- a/src/jcgp/function/Addition.java
+++ b/src/jcgp/function/Addition.java
@@ -9,7 +9,7 @@ public class Addition extends Function {
if (connections.length > 0) {
return connections[0].getValue() + connections[1].getValue();
} else {
- return 0;
+ throw new InsufficientArgumentsException();
}
}
diff --git a/src/jcgp/function/Function.java b/src/jcgp/function/Function.java
index f2d1125..4900c68 100644
--- a/src/jcgp/function/Function.java
+++ b/src/jcgp/function/Function.java
@@ -1,10 +1,11 @@
package jcgp.function;
import jcgp.population.Connection;
+import jcgp.population.InsufficientConnectionsException;
public abstract class Function {
- public abstract int run(Connection ... connections);
+ public abstract int run(Connection ... connections) throws InsufficientConnectionsException;
public abstract int getArity();
diff --git a/src/jcgp/function/InsufficientArgumentsException.java b/src/jcgp/function/InsufficientArgumentsException.java
new file mode 100644
index 0000000..a591b20
--- /dev/null
+++ b/src/jcgp/function/InsufficientArgumentsException.java
@@ -0,0 +1,10 @@
+package jcgp.function;
+
+public class InsufficientArgumentsException extends RuntimeException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 2675108124600817777L;
+
+}
diff --git a/src/jcgp/function/Subtraction.java b/src/jcgp/function/Subtraction.java
index f8b9c7d..8f107b1 100644
--- a/src/jcgp/function/Subtraction.java
+++ b/src/jcgp/function/Subtraction.java
@@ -9,7 +9,7 @@ public class Subtraction extends Function {
if (connections.length > 1) {
return connections[0].getValue() - connections[1].getValue();
} else {
- return 0;
+ throw new InsufficientArgumentsException();
}
}