52 lines
1.2 KiB
Java
52 lines
1.2 KiB
Java
package function.builtin.math;
|
|
|
|
import static testutil.TestUtilities.*;
|
|
|
|
import org.junit.Test;
|
|
|
|
import function.ArgumentValidator.*;
|
|
import sexpression.LispNumber;
|
|
import testutil.SymbolAndFunctionCleaner;
|
|
|
|
public class MINUSTest extends SymbolAndFunctionCleaner {
|
|
|
|
@Test
|
|
public void minusWithOneNumber() {
|
|
String input = "(- 27)";
|
|
|
|
assertSExpressionsMatch(new LispNumber("-27"), evaluateString(input));
|
|
}
|
|
|
|
@Test
|
|
public void minusWithTwoNumbers() {
|
|
String input = "(- 5 3)";
|
|
|
|
assertSExpressionsMatch(new LispNumber("2"), evaluateString(input));
|
|
}
|
|
|
|
@Test
|
|
public void minusWithManyNumbers_PositiveResult() {
|
|
String input = "(- 200 100 10 5)";
|
|
|
|
assertSExpressionsMatch(new LispNumber("85"), evaluateString(input));
|
|
}
|
|
|
|
@Test
|
|
public void minusWithManyNumbers_NegativeResult() {
|
|
String input = "(- 100 200 20 5)";
|
|
|
|
assertSExpressionsMatch(new LispNumber("-125"), evaluateString(input));
|
|
}
|
|
|
|
@Test(expected = BadArgumentTypeException.class)
|
|
public void minusWithNonNumber() {
|
|
evaluateString("(- 'a 'b)");
|
|
}
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
|
public void minusWithTooFewArguments() {
|
|
evaluateString("(-)");
|
|
}
|
|
|
|
}
|