transcendental-lisp/test/table/SymbolTableTester.java

62 lines
1.3 KiB
Java
Raw Normal View History

2016-12-19 13:29:31 -05:00
package table;
import static org.junit.Assert.*;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
2016-12-19 13:29:31 -05:00
import org.junit.*;
public class SymbolTableTester {
private SymbolTable symbolTable;
@Before
public void setUp() {
2016-12-19 13:29:31 -05:00
symbolTable = new SymbolTable();
}
@Test
public void lookupSymbolNotInTable() {
assertFalse(symbolTable.contains("symbol"));
}
@Test
public void lookupSymbolInTable() {
symbolTable.put("symbol", T);
2016-12-19 13:29:31 -05:00
assertTrue(symbolTable.contains("symbol"));
}
@Test
public void retrieveSymbolValue() {
symbolTable.put("symbol", T);
assertEquals(T, symbolTable.get("symbol"));
2016-12-19 13:29:31 -05:00
}
@Test
public void redefineSymbolValue() {
symbolTable.put("symbol", T);
symbolTable.put("symbol", NIL);
assertEquals(NIL, symbolTable.get("symbol"));
2016-12-19 13:29:31 -05:00
}
@Test
public void checkParentTableIsCorrect() {
SymbolTable childTable = new SymbolTable(symbolTable);
assertEquals(symbolTable, childTable.getParent());
2016-12-19 13:29:31 -05:00
}
@Test
public void lookupSymbolInParentTable() {
symbolTable.put("symbol", T);
2016-12-19 13:29:31 -05:00
SymbolTable childTable = new SymbolTable(symbolTable);
SymbolTable parentTable = childTable.getParent();
assertEquals(T, parentTable.get("symbol"));
2016-12-19 13:29:31 -05:00
}
}