From afa484021ba94d12e98da682a9ff69c3837d5dbb Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Fri, 14 Feb 2014 18:13:21 +0000 Subject: Generic data type functionality implemented. All tests were refactored to reflect this, and some chromosome tests were rewritten with more rigorous assertions. --- src/jcgp/function/Subtraction.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/jcgp/function/Subtraction.java') diff --git a/src/jcgp/function/Subtraction.java b/src/jcgp/function/Subtraction.java index 8f107b1..d785614 100644 --- a/src/jcgp/function/Subtraction.java +++ b/src/jcgp/function/Subtraction.java @@ -4,18 +4,22 @@ import jcgp.population.Connection; public class Subtraction extends Function { + private int arity = 2; + @Override - public int run(Connection... connections) { - if (connections.length > 1) { - return connections[0].getValue() - connections[1].getValue(); + public Object run(Connection... connections) { + if (connections.length < arity) { + throw new InvalidArgumentsException("Not enough connections were given."); + } else if (connections[0].getValue() instanceof Integer) { + return ((Integer) connections[0].getValue()) - ((Integer) connections[1].getValue()); } else { - throw new InsufficientArgumentsException(); + throw new InvalidArgumentsException("Wrong data type, this function takes Integer."); } } @Override public int getArity() { - return 2; + return arity; } } -- cgit v1.2.3