2017-01-22 11:11:16 -05:00
|
|
|
package function.builtin;
|
|
|
|
|
2017-03-03 12:07:23 -05:00
|
|
|
import static error.ErrorManager.Severity.ERROR;
|
2017-01-22 11:11:16 -05:00
|
|
|
import static org.junit.Assert.*;
|
2017-03-02 09:54:23 -05:00
|
|
|
import static sexpression.Nil.NIL;
|
2017-01-22 11:11:16 -05:00
|
|
|
import static testutil.TestUtilities.evaluateString;
|
|
|
|
|
2017-07-19 15:23:15 -04:00
|
|
|
import org.junit.Test;
|
2017-01-22 11:11:16 -05:00
|
|
|
|
|
|
|
import function.ArgumentValidator.*;
|
|
|
|
import function.builtin.SYMBOL_FUNCTION.UndefinedSymbolFunctionException;
|
2017-07-19 15:23:15 -04:00
|
|
|
import testutil.SymbolAndFunctionCleaner;
|
2017-01-22 11:11:16 -05:00
|
|
|
|
2017-07-19 15:23:15 -04:00
|
|
|
public class SYMBOL_FUNCTIONTest extends SymbolAndFunctionCleaner {
|
2017-02-06 12:02:19 -05:00
|
|
|
|
2017-01-22 11:11:16 -05:00
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void symbolFunction_BuiltInFunction() {
|
2017-01-22 11:11:16 -05:00
|
|
|
String input = "(symbol-function '+)";
|
|
|
|
|
2017-02-27 14:10:20 -05:00
|
|
|
assertEquals("#<FUNCTION +>", evaluateString(input).toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void symbolFunction_BuiltInSpecialFunction() {
|
2017-02-27 14:10:20 -05:00
|
|
|
String input = "(symbol-function 'if)";
|
|
|
|
|
|
|
|
assertEquals("#<SPECIAL-FUNCTION IF>", evaluateString(input).toString());
|
2017-01-22 11:11:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void symbolFunction_UserDefinedFunction() {
|
2017-01-22 11:11:16 -05:00
|
|
|
String defineUserFunction = "(defun y (n m) (+ n m))";
|
|
|
|
String input = "(symbol-function 'y)";
|
|
|
|
|
|
|
|
evaluateString(defineUserFunction);
|
|
|
|
assertEquals("(Y (N M) (+ N M))", evaluateString(input).toString());
|
|
|
|
}
|
|
|
|
|
2017-02-09 12:09:51 -05:00
|
|
|
@Test(expected = UndefinedSymbolFunctionException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void symbolFunction_NonFunction() {
|
2017-01-22 11:11:16 -05:00
|
|
|
String input = "(symbol-function 'a)";
|
|
|
|
|
|
|
|
evaluateString(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = BadArgumentTypeException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void symbolFunctionWithBadArgumentType() {
|
2017-01-22 11:11:16 -05:00
|
|
|
evaluateString("(symbol-function 2)");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooManyArgumentsException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void symbolFunctionWithTooManyArguments() {
|
2017-01-22 11:11:16 -05:00
|
|
|
evaluateString("(symbol-function 'a 'b)");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void symbolFunctionWithTooFewArguments() {
|
2017-01-22 11:11:16 -05:00
|
|
|
evaluateString("(symbol-function)");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-03-03 12:07:23 -05:00
|
|
|
public void undefinedSymbolFunctionException_HasCorrectAttributes() {
|
2017-03-02 09:54:23 -05:00
|
|
|
UndefinedSymbolFunctionException e = new UndefinedSymbolFunctionException(NIL);
|
2017-01-22 11:11:16 -05:00
|
|
|
|
2017-03-03 12:07:23 -05:00
|
|
|
assertEquals(ERROR, e.getSeverity());
|
2017-01-22 11:11:16 -05:00
|
|
|
assertNotNull(e.getMessage());
|
|
|
|
assertTrue(e.getMessage().length() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|