69 lines
2.1 KiB
Java
69 lines
2.1 KiB
Java
|
package function.builtin.special;
|
||
|
|
||
|
import static org.junit.Assert.*;
|
||
|
import static testutil.TestUtilities.*;
|
||
|
|
||
|
import org.junit.Test;
|
||
|
|
||
|
import function.ArgumentValidator.*;
|
||
|
import sexpression.*;
|
||
|
|
||
|
public class LAMBDATester {
|
||
|
|
||
|
@Test
|
||
|
public void testLambda() {
|
||
|
String input = "(lambda (x) x)";
|
||
|
|
||
|
assertSExpressionsMatch(parseString("(LAMBDA (X) X)"), evaluateString(input));
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void lambdaExpressionIsLambdaExpression() {
|
||
|
Cons lambdaExpression = new Cons(new Symbol("LAMBDA"),
|
||
|
new Cons(Nil.getInstance(), new Cons(Nil.getInstance(), Nil.getInstance())));
|
||
|
|
||
|
assertTrue(LAMBDA.isLambdaExpression(lambdaExpression));
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void somethingElseIsNotLambdaExpression() {
|
||
|
assertFalse(LAMBDA.isLambdaExpression(Symbol.T));
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void testCreateLambdaExpression() {
|
||
|
Cons lambdaExpression = new Cons(new Symbol("LAMBDA"),
|
||
|
new Cons(Nil.getInstance(), new Cons(Nil.getInstance(), Nil.getInstance())));
|
||
|
|
||
|
assertSExpressionsMatch(parseString("(:LAMBDA () ())"),
|
||
|
LAMBDA.createFunction(lambdaExpression).getLambdaExpression());
|
||
|
}
|
||
|
|
||
|
@Test(expected = DottedArgumentListException.class)
|
||
|
public void testLambdaWithDottedArgumentList() {
|
||
|
String input = "(apply 'lambda (cons '(x) 1))";
|
||
|
|
||
|
evaluateString(input);
|
||
|
}
|
||
|
|
||
|
@Test(expected = DottedArgumentListException.class)
|
||
|
public void testCreateFunctionWithDottedArgumentList() {
|
||
|
Cons lambdaExpression = new Cons(new Symbol("LAMBDA"), new Cons(Nil.getInstance(), LispNumber.ONE));
|
||
|
|
||
|
LAMBDA.createFunction(lambdaExpression);
|
||
|
}
|
||
|
|
||
|
@Test(expected = BadArgumentTypeException.class)
|
||
|
public void testCreateFunctionWithNonList() {
|
||
|
Cons lambdaExpression = new Cons(new Symbol("LAMBDA"), LispNumber.ONE);
|
||
|
|
||
|
LAMBDA.createFunction(lambdaExpression);
|
||
|
}
|
||
|
|
||
|
@Test(expected = TooFewArgumentsException.class)
|
||
|
public void testLambdaWithTooFewArguments() {
|
||
|
evaluateString("(lambda ())");
|
||
|
}
|
||
|
|
||
|
}
|