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.BadArgumentTypeException;
|
|
|
|
import sexpression.LispNumber;
|
|
|
|
|
|
|
|
public class MULTIPLYTester {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testMultiplyWithNoArguments() {
|
|
|
|
String input = "(*)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(new LispNumber("1"), evaluateString(input));
|
2017-01-13 14:05:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testMultiplyWithOneNumber() {
|
|
|
|
String input = "(* 8)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(new LispNumber("8"), evaluateString(input));
|
2017-01-13 14:05:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testMultiplyWithTwoNumbers() {
|
|
|
|
String input = "(* 5 3)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(new LispNumber("15"), evaluateString(input));
|
2017-01-13 14:05:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testMultiplyWithManyNumbers_PositiveResult() {
|
|
|
|
String input = "(* 2 3 5 1)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(new LispNumber("30"), evaluateString(input));
|
2017-01-13 14:05:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testMultiplyWithManyNumbers_NegativeResult() {
|
|
|
|
String input = "(* 3 (- 2) 10 2)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(new LispNumber("-120"), evaluateString(input));
|
2017-01-13 14:05:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = BadArgumentTypeException.class)
|
|
|
|
public void testMultiplyWithNonNumber() {
|
|
|
|
evaluateString("(* 'a 'b)");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|