transcendental-lisp/test/function/builtin/math/PLUSTest.java

55 lines
1.4 KiB
Java
Raw Normal View History

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