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.*;
|
|
|
|
|
2017-02-24 16:00:05 -05:00
|
|
|
public class RESTTester {
|
2016-12-23 10:53:11 -05:00
|
|
|
|
|
|
|
@Test
|
2017-02-24 16:00:05 -05:00
|
|
|
public void restOfNil() {
|
|
|
|
String input = "(rest nil)";
|
2016-12-23 10:53:11 -05:00
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("()"), evaluateString(input));
|
2016-12-23 10:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-02-24 16:00:05 -05:00
|
|
|
public void restOfList() {
|
|
|
|
String input = "(rest '(1 2 3))";
|
|
|
|
|
|
|
|
assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void cdrOfList() {
|
2016-12-23 10:53:11 -05:00
|
|
|
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
|
2017-02-24 16:00:05 -05:00
|
|
|
public void nestedRestOfList() {
|
|
|
|
String input = "(rest (rest '(1 2 3)))";
|
2016-12-23 10:53:11 -05:00
|
|
|
|
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)
|
2017-02-24 16:00:05 -05:00
|
|
|
public void restOfSymbol() {
|
|
|
|
evaluateString("(rest 'x)");
|
2016-12-23 10:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooManyArgumentsException.class)
|
2017-02-24 16:00:05 -05:00
|
|
|
public void restWithTooManyArguments() {
|
|
|
|
evaluateString("(rest '(1 2) '(1 2) \"oh\")");
|
2016-12-23 10:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
2017-02-24 16:00:05 -05:00
|
|
|
public void restWithTooFewArguments() {
|
|
|
|
evaluateString("(rest)");
|
2016-12-23 10:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|