2016-12-23 10:53:11 -05:00
|
|
|
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() {
|
2016-12-25 13:29:06 -05:00
|
|
|
evaluateString("(cdr '(1 2) '(1 2) \"oh\")");
|
2016-12-23 10:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
2016-12-25 13:29:06 -05:00
|
|
|
public void testCdrWithTooFewArguments() {
|
|
|
|
evaluateString("(cdr)");
|
2016-12-23 10:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|