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

53 lines
1.2 KiB
Java
Raw Normal View History

package function.builtin.math;
import static testutil.TestUtilities.*;
import org.junit.Test;
import function.ArgumentValidator.BadArgumentTypeException;
import sexpression.LispNumber;
public class PLUSTester {
@Test
public void testPlusWithNoArguments() {
String input = "(+)";
assertSExpressionsMatch(new LispNumber("0"), evaluateString(input));
}
@Test
public void testPlusWithOneNumber() {
String input = "(+ 27)";
assertSExpressionsMatch(new LispNumber("27"), evaluateString(input));
}
@Test
public void testPlusWithTwoNumbers() {
String input = "(+ 5 3)";
assertSExpressionsMatch(new LispNumber("8"), evaluateString(input));
}
@Test
public void testPlusWithManyNumbers_PositiveResult() {
String input = "(+ 200 100 10 5)";
assertSExpressionsMatch(new LispNumber("315"), evaluateString(input));
}
@Test
public void testPlusWithManyNumbers_NegativeResult() {
String input = "(+ 100 (- 200) 20 5)";
assertSExpressionsMatch(new LispNumber("-75"), evaluateString(input));
}
@Test(expected = BadArgumentTypeException.class)
public void testPlusWithNonNumber() {
evaluateString("(+ 'a 'b)");
}
}