55 lines
1.2 KiB
Java
55 lines
1.2 KiB
Java
|
package function.builtin.cons;
|
||
|
|
||
|
import static testutil.TestUtilities.*;
|
||
|
|
||
|
import org.junit.Test;
|
||
|
|
||
|
import function.ArgumentValidator.*;
|
||
|
|
||
|
public class FIRSTTester {
|
||
|
|
||
|
@Test
|
||
|
public void firstOfNil() {
|
||
|
String input = "(first nil)";
|
||
|
|
||
|
assertSExpressionsMatch(parseString("()"), evaluateString(input));
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void firstOfList() {
|
||
|
String input = "(first '(1 2 3))";
|
||
|
|
||
|
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void carOfList() {
|
||
|
String input = "(car '(1 2 3))";
|
||
|
|
||
|
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void nestedFirstOfList() {
|
||
|
String input = "(first (first '((1 2) 3)))";
|
||
|
|
||
|
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
||
|
}
|
||
|
|
||
|
@Test(expected = BadArgumentTypeException.class)
|
||
|
public void firstOfSymbol() {
|
||
|
evaluateString("(first 'x)");
|
||
|
}
|
||
|
|
||
|
@Test(expected = TooManyArgumentsException.class)
|
||
|
public void firstWithTooManyArguments() {
|
||
|
evaluateString("(first '(1 2) '(1 2) \"oh\")");
|
||
|
}
|
||
|
|
||
|
@Test(expected = TooFewArgumentsException.class)
|
||
|
public void firstWithTooFewArguments() {
|
||
|
evaluateString("(first)");
|
||
|
}
|
||
|
|
||
|
}
|