package function.builtin; import static org.junit.Assert.*; import static testutil.TestUtilities.evaluateString; import org.junit.Test; import function.ArgumentValidator.*; import function.builtin.SYMBOL_FUNCTION.UndefinedSymbolFunctionException; import sexpression.Nil; public class SYMBOL_FUNCTIONTester { @Test public void testSymbolFunction_BuiltinFunction() { String input = "(symbol-function '+)"; assertEquals("#", evaluateString(input).toString()); } @Test public void testSymbolFunction_UserDefinedFunction() { String defineUserFunction = "(defun y (n m) (+ n m))"; String input = "(symbol-function 'y)"; evaluateString(defineUserFunction); assertEquals("(Y (N M) (+ N M))", evaluateString(input).toString()); } @Test(expected = RuntimeException.class) public void testSymbolFunction_NonFunction() { String input = "(symbol-function 'a)"; evaluateString(input); } @Test(expected = BadArgumentTypeException.class) public void testSymbolFunctionWithBadArgumentType() { evaluateString("(symbol-function 2)"); } @Test(expected = TooManyArgumentsException.class) public void testSymbolFunctionWithTooManyArguments() { evaluateString("(symbol-function 'a 'b)"); } @Test(expected = TooFewArgumentsException.class) public void testSymbolFunctionWithTooFewArguments() { evaluateString("(symbol-function)"); } @Test public void undefinedSymbolFunctionException_HasMessageText() { UndefinedSymbolFunctionException e = new UndefinedSymbolFunctionException(Nil.getInstance()); assertNotNull(e.getMessage()); assertTrue(e.getMessage().length() > 0); } }