2017-01-14 18:01:14 -05:00
|
|
|
package function.builtin.cons;
|
2016-12-23 10:53:11 -05:00
|
|
|
|
|
|
|
import static testutil.TestUtilities.*;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import function.ArgumentValidator.*;
|
|
|
|
|
|
|
|
public class CDRTester {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCdrWithNil() {
|
|
|
|
String input = "(cdr nil)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("()"), evaluateString(input));
|
2016-12-23 10:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCdrWithList() {
|
|
|
|
String input = "(cdr '(1 2 3))";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input));
|
2016-12-23 10:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testNestedCdrWithList() {
|
|
|
|
String input = "(cdr (cdr '(1 2 3)))";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("(3)"), evaluateString(input));
|
2016-12-23 10:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
}
|
|
|
|
|
|
|
|
}
|