62 lines
1.6 KiB
Java
62 lines
1.6 KiB
Java
package function.builtin;
|
|
|
|
import static testutil.TestUtilities.*;
|
|
|
|
import org.junit.Test;
|
|
|
|
import function.ArgumentValidator.*;
|
|
import sexpression.Cons;
|
|
|
|
public class APPLYTester {
|
|
|
|
@Test
|
|
public void testApply() {
|
|
String input = "(apply '+ '(1 2 3))";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("6"));
|
|
}
|
|
|
|
@Test
|
|
public void testApplyWithLambdaExpression() {
|
|
String input = "(apply (lambda (x) (+ x 1)) '(25))";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("26"));
|
|
}
|
|
|
|
@Test
|
|
public void testApplyWithQuotedLambdaExpression() {
|
|
String input = "(apply '(lambda (x) (+ x 1)) '(25))";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("26"));
|
|
}
|
|
|
|
@Test
|
|
public void testStaticApplyCall() {
|
|
String argumentList = "(+ (25 10))";
|
|
Cons parsedArgumentList = (Cons) parseString(argumentList);
|
|
|
|
assertSExpressionsMatch(APPLY.apply(parsedArgumentList), parseString("35"));
|
|
}
|
|
|
|
@Test(expected = RuntimeException.class)
|
|
public void testApplyWithUndefinedFunction() {
|
|
evaluateString("(apply 'f '(1 2 3))");
|
|
}
|
|
|
|
@Test(expected = RuntimeException.class)
|
|
public void testApplyWithNonListSecondArgument() {
|
|
evaluateString("(apply '+ '2)");
|
|
}
|
|
|
|
@Test(expected = TooManyArgumentsException.class)
|
|
public void testApplyWithTooManyArguments() {
|
|
evaluateString("(apply '1 '2 '3)");
|
|
}
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
|
public void testApplyWithTooFewArguments() {
|
|
evaluateString("(apply '1)");
|
|
}
|
|
|
|
}
|