53 lines
1.2 KiB
Java
53 lines
1.2 KiB
Java
package function.builtin;
|
|
|
|
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(evaluateString(input), new LispNumber("0"));
|
|
}
|
|
|
|
@Test
|
|
public void testPlusWithOneNumber() {
|
|
String input = "(+ 27)";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), new LispNumber("27"));
|
|
}
|
|
|
|
@Test
|
|
public void testPlusWithTwoNumbers() {
|
|
String input = "(+ 5 3)";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), new LispNumber("8"));
|
|
}
|
|
|
|
@Test
|
|
public void testPlusWithManyNumbers_PositiveResult() {
|
|
String input = "(+ 200 100 10 5)";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), new LispNumber("315"));
|
|
}
|
|
|
|
@Test
|
|
public void testPlusWithManyNumbers_NegativeResult() {
|
|
String input = "(+ 100 (- 200) 20 5)";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), new LispNumber("-75"));
|
|
}
|
|
|
|
@Test(expected = BadArgumentTypeException.class)
|
|
public void testPlusWithNonNumber() {
|
|
evaluateString("(+ 'a 'b)");
|
|
}
|
|
|
|
}
|