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;
|
2017-07-19 15:23:15 -04:00
|
|
|
import testutil.SymbolAndFunctionCleaner;
|
2017-01-13 14:05:33 -05:00
|
|
|
|
2017-07-19 15:23:15 -04:00
|
|
|
public class MULTIPLYTest extends SymbolAndFunctionCleaner {
|
2017-01-13 14:05:33 -05:00
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void multiplyWithNoArguments() {
|
2017-01-13 14:05:33 -05:00
|
|
|
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
|
2017-03-02 09:54:23 -05:00
|
|
|
public void multiplyWithOneNumber() {
|
2017-01-13 14:05:33 -05:00
|
|
|
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
|
2017-03-02 09:54:23 -05:00
|
|
|
public void multiplyWithTwoNumbers() {
|
2017-01-13 14:05:33 -05:00
|
|
|
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
|
2017-03-02 09:54:23 -05:00
|
|
|
public void multiplyWithManyNumbers_PositiveResult() {
|
2017-01-13 14:05:33 -05:00
|
|
|
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
|
2017-03-02 09:54:23 -05:00
|
|
|
public void multiplyWithManyNumbers_NegativeResult() {
|
2017-01-13 14:05:33 -05:00
|
|
|
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)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void multiplyWithNonNumber() {
|
2017-01-13 14:05:33 -05:00
|
|
|
evaluateString("(* 'a 'b)");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|