2017-01-04 13:57:16 -05:00
|
|
|
package function.builtin;
|
|
|
|
|
2017-03-03 15:06:49 -05:00
|
|
|
import static table.FunctionTable.resetFunctionTable;
|
2017-01-04 13:57:16 -05:00
|
|
|
import static testutil.TestUtilities.*;
|
|
|
|
|
2017-02-06 12:02:19 -05:00
|
|
|
import org.junit.*;
|
2017-01-04 13:57:16 -05:00
|
|
|
|
|
|
|
import function.ArgumentValidator.TooFewArgumentsException;
|
|
|
|
|
|
|
|
public class FUNCALLTester {
|
|
|
|
|
2017-02-06 12:02:19 -05:00
|
|
|
@Before
|
|
|
|
public void setUp() {
|
2017-03-03 15:06:49 -05:00
|
|
|
resetFunctionTable();
|
2017-02-06 12:02:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@After
|
|
|
|
public void tearDown() {
|
2017-03-03 15:06:49 -05:00
|
|
|
resetFunctionTable();
|
2017-02-06 12:02:19 -05:00
|
|
|
}
|
|
|
|
|
2017-01-04 13:57:16 -05:00
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void funcallWithNumbers() {
|
2017-01-04 13:57:16 -05:00
|
|
|
String input = "(funcall '+ 1 2 3)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("6"), evaluateString(input));
|
2017-01-04 13:57:16 -05:00
|
|
|
}
|
|
|
|
|
2017-03-06 16:52:06 -05:00
|
|
|
@Test
|
|
|
|
public void callWithNumbers() {
|
|
|
|
String input = "(call '+ 1 2 3)";
|
|
|
|
|
|
|
|
assertSExpressionsMatch(parseString("6"), evaluateString(input));
|
|
|
|
}
|
|
|
|
|
2017-01-04 13:57:16 -05:00
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void funcallWithUserDefinedFunction() {
|
2017-01-04 13:57:16 -05:00
|
|
|
String defineUserFunction = "(defun x (n m) (+ n m))";
|
|
|
|
String input = "(funcall 'x 2 30)";
|
|
|
|
|
|
|
|
evaluateString(defineUserFunction);
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("32"), evaluateString(input));
|
2017-01-04 13:57:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void funcallWithTooFewArguments() {
|
2017-01-04 13:57:16 -05:00
|
|
|
evaluateString("(funcall)");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|