2017-01-14 18:01:14 -05:00
|
|
|
package function.builtin.math;
|
2017-01-13 14:05:33 -05:00
|
|
|
|
2017-11-12 09:42:25 -05:00
|
|
|
import static testutil.TestUtilities.assertSExpressionsMatch;
|
|
|
|
import static testutil.TestUtilities.evaluateString;
|
2017-01-13 14:05:33 -05:00
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import function.ArgumentValidator.BadArgumentTypeException;
|
|
|
|
import sexpression.LispNumber;
|
2017-07-19 15:23:15 -04:00
|
|
|
import testutil.SymbolAndFunctionCleaner;
|
2017-01-13 14:05:33 -05:00
|
|
|
|
2017-07-19 15:23:15 -04:00
|
|
|
public class PLUSTest extends SymbolAndFunctionCleaner {
|
2017-01-13 14:05:33 -05:00
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void plusWithNoArguments() {
|
2017-01-13 14:05:33 -05:00
|
|
|
String input = "(+)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(new LispNumber("0"), evaluateString(input));
|
2017-01-13 14:05:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void plusWithOneNumber() {
|
2017-01-13 14:05:33 -05:00
|
|
|
String input = "(+ 27)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(new LispNumber("27"), evaluateString(input));
|
2017-01-13 14:05:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void plusWithTwoNumbers() {
|
2017-01-13 14:05:33 -05:00
|
|
|
String input = "(+ 5 3)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(new LispNumber("8"), evaluateString(input));
|
2017-01-13 14:05:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void plusWithManyNumbers_PositiveResult() {
|
2017-01-13 14:05:33 -05:00
|
|
|
String input = "(+ 200 100 10 5)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(new LispNumber("315"), evaluateString(input));
|
2017-01-13 14:05:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void plusWithManyNumbers_NegativeResult() {
|
2017-01-13 14:05:33 -05:00
|
|
|
String input = "(+ 100 (- 200) 20 5)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(new LispNumber("-75"), evaluateString(input));
|
2017-01-13 14:05:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = BadArgumentTypeException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void plusWithNonNumber() {
|
2017-01-13 14:05:33 -05:00
|
|
|
evaluateString("(+ 'a 'b)");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|