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

53 lines
1.2 KiB
Java

package function.builtin.math;
import static testutil.TestUtilities.*;
import org.junit.Test;
import function.ArgumentValidator.BadArgumentTypeException;
import sexpression.LispNumber;
public class MULTIPLYTest {
@Test
public void multiplyWithNoArguments() {
String input = "(*)";
assertSExpressionsMatch(new LispNumber("1"), evaluateString(input));
}
@Test
public void multiplyWithOneNumber() {
String input = "(* 8)";
assertSExpressionsMatch(new LispNumber("8"), evaluateString(input));
}
@Test
public void multiplyWithTwoNumbers() {
String input = "(* 5 3)";
assertSExpressionsMatch(new LispNumber("15"), evaluateString(input));
}
@Test
public void multiplyWithManyNumbers_PositiveResult() {
String input = "(* 2 3 5 1)";
assertSExpressionsMatch(new LispNumber("30"), evaluateString(input));
}
@Test
public void multiplyWithManyNumbers_NegativeResult() {
String input = "(* 3 (- 2) 10 2)";
assertSExpressionsMatch(new LispNumber("-120"), evaluateString(input));
}
@Test(expected = BadArgumentTypeException.class)
public void multiplyWithNonNumber() {
evaluateString("(* 'a 'b)");
}
}