2017-01-14 18:01:14 -05:00
|
|
|
package function.builtin.math;
|
2017-01-13 14:05:33 -05:00
|
|
|
|
|
|
|
import static testutil.TestUtilities.*;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import function.ArgumentValidator.BadArgumentTypeException;
|
|
|
|
import sexpression.LispNumber;
|
|
|
|
|
|
|
|
public class PLUSTester {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testPlusWithNoArguments() {
|
|
|
|
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
|
|
|
|
public void testPlusWithOneNumber() {
|
|
|
|
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
|
|
|
|
public void testPlusWithTwoNumbers() {
|
|
|
|
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
|
|
|
|
public void testPlusWithManyNumbers_PositiveResult() {
|
|
|
|
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
|
|
|
|
public void testPlusWithManyNumbers_NegativeResult() {
|
|
|
|
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)
|
|
|
|
public void testPlusWithNonNumber() {
|
|
|
|
evaluateString("(+ 'a 'b)");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|