2017-01-22 11:11:16 -05:00
|
|
|
package function.builtin;
|
|
|
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
import static testutil.TestUtilities.evaluateString;
|
|
|
|
|
2017-02-06 12:02:19 -05:00
|
|
|
import org.junit.*;
|
2017-01-22 11:11:16 -05:00
|
|
|
|
|
|
|
import function.ArgumentValidator.*;
|
|
|
|
import function.builtin.SYMBOL_FUNCTION.UndefinedSymbolFunctionException;
|
|
|
|
import sexpression.Nil;
|
2017-02-06 12:02:19 -05:00
|
|
|
import table.FunctionTable;
|
2017-01-22 11:11:16 -05:00
|
|
|
|
|
|
|
public class SYMBOL_FUNCTIONTester {
|
|
|
|
|
2017-02-06 12:02:19 -05:00
|
|
|
@Before
|
|
|
|
public void setUp() {
|
|
|
|
FunctionTable.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
@After
|
|
|
|
public void tearDown() {
|
|
|
|
FunctionTable.reset();
|
|
|
|
}
|
|
|
|
|
2017-01-22 11:11:16 -05:00
|
|
|
@Test
|
|
|
|
public void testSymbolFunction_BuiltinFunction() {
|
|
|
|
String input = "(symbol-function '+)";
|
|
|
|
|
|
|
|
assertEquals("#<SYSTEM-FUNCTION +>", 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|