52 lines
1.2 KiB
Java
52 lines
1.2 KiB
Java
package function.builtin;
|
|
|
|
import static testutil.TestUtilities.*;
|
|
|
|
import org.junit.Test;
|
|
|
|
import function.ArgumentValidator.*;
|
|
|
|
public class CDRTester {
|
|
|
|
@Test
|
|
public void testCdrWithNil() {
|
|
String input = "(cdr nil)";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("()"));
|
|
}
|
|
|
|
@Test
|
|
public void testCdrWithList() {
|
|
String input = "(cdr '(1 2 3))";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("(2 3)"));
|
|
}
|
|
|
|
@Test
|
|
public void testNestedCdrWithList() {
|
|
String input = "(cdr (cdr '(1 2 3)))";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("(3)"));
|
|
}
|
|
|
|
@Test(expected = BadArgumentTypeException.class)
|
|
public void testCdrWithNonList() {
|
|
evaluateString("(cdr 'x)");
|
|
}
|
|
|
|
@Test(expected = TooManyArgumentsException.class)
|
|
public void testCdrWithTooManyArguments() {
|
|
String input = "(cdr '(1 2) '(1 2) \"oh\")";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("1"));
|
|
}
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
|
public void testCdrWithTooFewArguments() {
|
|
String input = "(cdr)";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("1"));
|
|
}
|
|
|
|
}
|