package function.builtin.cons; 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(parseString("(())"), evaluateString(input)); } @Test public void testConsWithTwoSymbols() { String input = "(cons 'a 'b)"; assertSExpressionsMatch(new Cons(new Symbol("A"), new Symbol("B")), evaluateString(input)); } @Test public void testConsWithListAsCdr() { String input = "(cons 1 '(2 3))"; assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString(input)); } @Test public void testConsWithTwoLists() { String input = "(cons '(1 2) '(3 4))"; assertSExpressionsMatch(parseString("((1 2) 3 4)"), evaluateString(input)); } @Test public void testConsWithList() { String input = "(cons nil '(2 3))"; assertSExpressionsMatch(parseString("(nil 2 3)"), evaluateString(input)); } @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); } }