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

80 lines
2.3 KiB
Java
Raw Normal View History

2018-03-14 20:32:01 -04:00
package function.builtin.cons;
import static testutil.TestUtilities.assertSExpressionsMatch;
import static testutil.TestUtilities.evaluateString;
import static testutil.TestUtilities.parseString;
import org.junit.Test;
import function.ArgumentValidator.BadArgumentTypeException;
2018-03-14 21:01:39 -04:00
import function.ArgumentValidator.DottedArgumentListException;
2018-03-14 20:32:01 -04:00
import function.ArgumentValidator.TooFewArgumentsException;
import function.ArgumentValidator.TooManyArgumentsException;
import testutil.SymbolAndFunctionCleaner;
public class APPENDTest extends SymbolAndFunctionCleaner {
@Test
public void appendNil() {
String input = "(append () ())";
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
}
@Test
public void appendNilToList() {
String input = "(append () '(1 2 3))";
assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString(input));
}
@Test
public void appendListToNil() {
String input = "(append '(1 2 3) ())";
assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString(input));
}
@Test
public void appendTwoLists() {
String input = "(append '(1 2 3) '(4 5 6))";
assertSExpressionsMatch(parseString("(1 2 3 4 5 6)"), evaluateString(input));
}
@Test
2018-03-15 08:25:42 -04:00
public void appendMakesCopyOfFirstList() {
2018-03-14 20:32:01 -04:00
evaluateString("(setq x '(1 2 3))");
evaluateString("(setq y '(4 5 6))");
evaluateString("(append x y)");
assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString("x"));
}
2018-03-15 08:25:42 -04:00
@Test
public void appendAllowsDottedSecondList() {
String input = "(append '() (cons 3 4))";
assertSExpressionsMatch(evaluateString("(cons 3 4)"), evaluateString(input));
2018-03-14 21:01:39 -04:00
}
@Test(expected = DottedArgumentListException.class)
2018-03-15 08:25:42 -04:00
public void appendWithDottedFirstList() {
2018-03-14 21:01:39 -04:00
evaluateString("(append (cons 1 2) '(3 4))");
}
2018-03-14 20:32:01 -04:00
@Test(expected = TooManyArgumentsException.class)
public void appendWithTooManyArguments() {
evaluateString("(append () () ())");
}
@Test(expected = TooFewArgumentsException.class)
public void appendWithTooFewArguments() {
evaluateString("(append ())");
}
@Test(expected = BadArgumentTypeException.class)
public void appendWithBadArgumentType() {
evaluateString("(append 1 '(2))");
}
}