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 appendMakesCopyOfFirstList() { evaluateString("(setq x '(1 2 3))"); evaluateString("(setq y '(4 5 6))"); evaluateString("(append x y)"); assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString("x")); } @Test public void appendAllowsDottedSecondList() { String input = "(append '() (cons 3 4))"; assertSExpressionsMatch(evaluateString("(cons 3 4)"), evaluateString(input)); } @Test(expected = DottedArgumentListException.class) public void appendWithDottedFirstList() { 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))"); } }