transcendental-lisp/test/function/builtin/cons/RESTTest.java

60 lines
1.6 KiB
Java
Raw Normal View History

package function.builtin.cons;
2017-11-12 09:42:25 -05:00
import static testutil.TestUtilities.assertSExpressionsMatch;
import static testutil.TestUtilities.evaluateString;
import static testutil.TestUtilities.parseString;
import org.junit.Test;
2017-11-12 09:42:25 -05:00
import function.ArgumentValidator.BadArgumentTypeException;
import function.ArgumentValidator.TooFewArgumentsException;
import function.ArgumentValidator.TooManyArgumentsException;
import testutil.SymbolAndFunctionCleaner;
public class RESTTest extends SymbolAndFunctionCleaner {
@Test
public void restOfNil() {
String input = "(rest nil)";
assertSExpressionsMatch(parseString("()"), evaluateString(input));
}
@Test
public void restOfList() {
String input = "(rest '(1 2 3))";
assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input));
}
@Test
public void cdrOfList() {
String input = "(cdr '(1 2 3))";
assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input));
}
@Test
public void nestedRestOfList() {
String input = "(rest (rest '(1 2 3)))";
assertSExpressionsMatch(parseString("(3)"), evaluateString(input));
}
@Test(expected = BadArgumentTypeException.class)
public void restOfSymbol() {
evaluateString("(rest 'x)");
}
@Test(expected = TooManyArgumentsException.class)
public void restWithTooManyArguments() {
evaluateString("(rest '(1 2) '(1 2) \"oh\")");
}
@Test(expected = TooFewArgumentsException.class)
public void restWithTooFewArguments() {
evaluateString("(rest)");
}
}