78 lines
1.9 KiB
Java
78 lines
1.9 KiB
Java
package table;
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
import org.junit.*;
|
|
|
|
import function.LispFunction;
|
|
import sexpression.*;
|
|
|
|
public class FunctionTableTester {
|
|
|
|
private LispFunction createLispFunction() {
|
|
return new LispFunction() {
|
|
|
|
@Override
|
|
public SExpression call(Cons argList) {
|
|
return Symbol.T;
|
|
}
|
|
};
|
|
}
|
|
|
|
@Before
|
|
public void setUp() {
|
|
FunctionTable.reset();
|
|
}
|
|
|
|
@After
|
|
public void tearDown() {
|
|
FunctionTable.reset();
|
|
}
|
|
|
|
@Test
|
|
public void builtinFunctionIsDefined() {
|
|
assertTrue(FunctionTable.isAlreadyDefined("CONS"));
|
|
}
|
|
|
|
@Test
|
|
public void undefinedFunctionIsNotDefined() {
|
|
assertFalse(FunctionTable.isAlreadyDefined("undefined"));
|
|
}
|
|
|
|
@Test
|
|
public void lookupBuiltinFunction_ReturnsFunction() {
|
|
assertNotNull(FunctionTable.lookupFunction("CONS"));
|
|
}
|
|
|
|
@Test
|
|
public void lookupUndefinedFunction_ReturnsNull() {
|
|
assertNull(FunctionTable.lookupFunction("undefined"));
|
|
}
|
|
|
|
@Test
|
|
public void defineFunction() {
|
|
String functionName = "testFunction";
|
|
LispFunction testFunction = createLispFunction();
|
|
|
|
assertNull(FunctionTable.lookupFunction(functionName));
|
|
assertFalse(FunctionTable.isAlreadyDefined(functionName));
|
|
|
|
FunctionTable.defineFunction(functionName, testFunction);
|
|
|
|
assertTrue(FunctionTable.isAlreadyDefined(functionName));
|
|
assertEquals(testFunction, FunctionTable.lookupFunction(functionName));
|
|
}
|
|
|
|
@Test
|
|
public void resetFunctionTable() {
|
|
String functionName = "testFunction";
|
|
LispFunction testFunction = createLispFunction();
|
|
FunctionTable.defineFunction(functionName, testFunction);
|
|
FunctionTable.reset();
|
|
|
|
assertFalse(FunctionTable.isAlreadyDefined(functionName));
|
|
assertNull(FunctionTable.lookupFunction(functionName));
|
|
}
|
|
|
|
}
|