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

53 lines
1.3 KiB
Java
Raw Normal View History

package function.builtin.math;
import static testutil.TestUtilities.*;
import org.junit.Test;
import function.ArgumentValidator.BadArgumentTypeException;
import sexpression.LispNumber;
public class MULTIPLYTester {
@Test
public void testMultiplyWithNoArguments() {
String input = "(*)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("1"));
}
@Test
public void testMultiplyWithOneNumber() {
String input = "(* 8)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("8"));
}
@Test
public void testMultiplyWithTwoNumbers() {
String input = "(* 5 3)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("15"));
}
@Test
public void testMultiplyWithManyNumbers_PositiveResult() {
String input = "(* 2 3 5 1)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("30"));
}
@Test
public void testMultiplyWithManyNumbers_NegativeResult() {
String input = "(* 3 (- 2) 10 2)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("-120"));
}
@Test(expected = BadArgumentTypeException.class)
public void testMultiplyWithNonNumber() {
evaluateString("(* 'a 'b)");
}
}