package function.builtin; import static testutil.TestUtilities.*; import org.junit.Test; import function.ArgumentValidator.*; import sexpression.*; public class CONSTester { @Test public void testConsWithNilValues() { String input = "(cons () nil)"; assertSExpressionsMatch(evaluateString(input), parseString("(())")); } @Test public void testConsWithTwoSymbols() { String input = "(cons 'a 'b)"; assertSExpressionsMatch(evaluateString(input), new Cons(new Symbol("A"), new Symbol("B"))); } @Test public void testConsWithListAsCdr() { String input = "(cons 1 '(2 3))"; assertSExpressionsMatch(evaluateString(input), parseString("(1 2 3)")); } @Test public void testConsWithTwoLists() { String input = "(cons '(1 2) '(3 4))"; assertSExpressionsMatch(evaluateString(input), parseString("((1 2) 3 4)")); } @Test public void testConsWithList() { String input = "(cons nil '(2 3))"; assertSExpressionsMatch(evaluateString(input), parseString("(nil 2 3)")); } @Test(expected = TooManyArgumentsException.class) public void testConsWithTooManyArguments() { String input = "(cons 1 2 3)"; evaluateString(input); } @Test(expected = TooFewArgumentsException.class) public void testConsWithTooFewArguments() { String input = "(cons 1)"; evaluateString(input); } }