80 lines
2.3 KiB
Java
80 lines
2.3 KiB
Java
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;
|
|
import function.ArgumentValidator.DottedArgumentListException;
|
|
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
|
|
public void appendMakesCopies() {
|
|
evaluateString("(setq x '(1 2 3))");
|
|
evaluateString("(setq y '(4 5 6))");
|
|
evaluateString("(append x y)");
|
|
|
|
assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString("x"));
|
|
assertSExpressionsMatch(parseString("(4 5 6)"), evaluateString("y"));
|
|
}
|
|
|
|
@Test(expected = DottedArgumentListException.class)
|
|
public void appendWithDottedFirstList() {
|
|
evaluateString("(append '(1 2) (cons 3 4))");
|
|
}
|
|
|
|
@Test(expected = DottedArgumentListException.class)
|
|
public void appendWithDottedSecondList() {
|
|
evaluateString("(append (cons 1 2) '(3 4))");
|
|
}
|
|
|
|
@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))");
|
|
}
|
|
}
|