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.TooFewArgumentsException; import function.ArgumentValidator.TooManyArgumentsException; import testutil.SymbolAndFunctionCleaner; public class FIRSTTest extends SymbolAndFunctionCleaner { @Test public void firstOfNil() { String input = "(first nil)"; assertSExpressionsMatch(parseString("()"), evaluateString(input)); } @Test public void firstOfList() { String input = "(first '(1 2 3))"; assertSExpressionsMatch(parseString("1"), evaluateString(input)); } @Test public void carOfList() { String input = "(car '(1 2 3))"; assertSExpressionsMatch(parseString("1"), evaluateString(input)); } @Test public void nestedFirstOfList() { String input = "(first (first '((1 2) 3)))"; assertSExpressionsMatch(parseString("1"), evaluateString(input)); } @Test(expected = BadArgumentTypeException.class) public void firstOfSymbol() { evaluateString("(first 'x)"); } @Test(expected = TooManyArgumentsException.class) public void firstWithTooManyArguments() { evaluateString("(first '(1 2) '(1 2) \"oh\")"); } @Test(expected = TooFewArgumentsException.class) public void firstWithTooFewArguments() { evaluateString("(first)"); } }