diff options
Diffstat (limited to 'src/jcgp/function')
-rw-r--r-- | src/jcgp/function/Addition.java | 2 | ||||
-rw-r--r-- | src/jcgp/function/Function.java | 3 | ||||
-rw-r--r-- | src/jcgp/function/InsufficientArgumentsException.java | 10 | ||||
-rw-r--r-- | src/jcgp/function/Subtraction.java | 2 |
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(); } } |