From 727801ab8002481fd2d213b45c3b43225b0f73bb Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Wed, 12 Feb 2014 11:57:18 +0000 Subject: Added a few more tests, be back after the meeting. --- src/jcgp/function/Addition.java | 2 +- src/jcgp/function/Function.java | 3 ++- src/jcgp/function/InsufficientArgumentsException.java | 10 ++++++++++ src/jcgp/function/Subtraction.java | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 src/jcgp/function/InsufficientArgumentsException.java (limited to 'src/jcgp/function') 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(); } } -- cgit v1.2.3