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.*;
|
|
|
|
import sexpression.LispNumber;
|
|
|
|
|
|
|
|
public class MINUSTester {
|
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void minusWithOneNumber() {
|
2017-01-13 14:05:33 -05:00
|
|
|
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
|
2017-03-02 09:54:23 -05:00
|
|
|
public void minusWithTwoNumbers() {
|
2017-01-13 14:05:33 -05:00
|
|
|
String input = "(- 5 3)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(new LispNumber("2"), evaluateString(input));
|
2017-01-13 14:05:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void minusWithManyNumbers_PositiveResult() {
|
2017-01-13 14:05:33 -05:00
|
|
|
String input = "(- 200 100 10 5)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(new LispNumber("85"), evaluateString(input));
|
2017-01-13 14:05:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void minusWithManyNumbers_NegativeResult() {
|
2017-01-13 14:05:33 -05:00
|
|
|
String input = "(- 100 200 20 5)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(new LispNumber("-125"), evaluateString(input));
|
2017-01-13 14:05:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = BadArgumentTypeException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void minusWithNonNumber() {
|
2017-01-13 14:05:33 -05:00
|
|
|
evaluateString("(- 'a 'b)");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void minusWithTooFewArguments() {
|
2017-01-13 14:05:33 -05:00
|
|
|
evaluateString("(-)");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|