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
|
|
|
|
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"));
|
|
|
|
}
|
|
|
|
|
2018-03-14 21:01:39 -04:00
|
|
|
@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))");
|
|
|
|
}
|
|
|
|
|
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))");
|
|
|
|
}
|
|
|
|
}
|