package function.builtin; import static testutil.TestUtilities.*; import org.junit.Test; import function.ArgumentValidator.*; public class CARTester { @Test public void testCarWithNil() { String input = "(car nil)"; assertSExpressionsMatch(evaluateString(input), parseString("()")); } @Test public void testCarWithList() { String input = "(car '(1 2 3))"; assertSExpressionsMatch(evaluateString(input), parseString("1")); } @Test public void testNestedCarWithList() { String input = "(car (car '((1 2) 3)))"; assertSExpressionsMatch(evaluateString(input), parseString("1")); } @Test(expected = BadArgumentTypeException.class) public void testCarWithNonList() { evaluateString("(car 'x)"); } @Test(expected = TooManyArgumentsException.class) public void testCarWithTooManyArguments() { String input = "(car '(1 2) '(1 2) \"oh\")"; assertSExpressionsMatch(evaluateString(input), parseString("1")); } @Test(expected = TooFewArgumentsException.class) public void testCarWithTooFewArguments() { String input = "(car)"; assertSExpressionsMatch(evaluateString(input), parseString("1")); } }