53 lines
1.2 KiB
Java
53 lines
1.2 KiB
Java
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 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)");
|
|
}
|
|
|
|
}
|