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

51 lines
1.2 KiB
Java
Raw Normal View History

package function.builtin.math;
import static testutil.TestUtilities.*;
import org.junit.Test;
import function.ArgumentValidator.*;
import sexpression.LispNumber;
public class MINUSTester {
@Test
public void testMinusWithOneNumber() {
String input = "(- 27)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("-27"));
}
@Test
public void testMinusWithTwoNumbers() {
String input = "(- 5 3)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("2"));
}
@Test
public void testMinusWithManyNumbers_PositiveResult() {
String input = "(- 200 100 10 5)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("85"));
}
@Test
public void testMinusWithManyNumbers_NegativeResult() {
String input = "(- 100 200 20 5)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("-125"));
}
@Test(expected = BadArgumentTypeException.class)
public void testMinusWithNonNumber() {
evaluateString("(- 'a 'b)");
}
@Test(expected = TooFewArgumentsException.class)
public void testMinusWithTooFewArguments() {
evaluateString("(-)");
}
}