package table; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static sexpression.Nil.NIL; import static sexpression.Symbol.T; import org.junit.Before; import org.junit.Test; public class SymbolTableTest { private SymbolTable symbolTable; @Before public void setUp() { symbolTable = new SymbolTable(); } @Test public void lookupSymbolNotInTable() { assertFalse(symbolTable.contains("symbol")); } @Test public void lookupSymbolInTable() { symbolTable.put("symbol", T); assertTrue(symbolTable.contains("symbol")); } @Test public void retrieveSymbolValue() { symbolTable.put("symbol", T); assertEquals(T, symbolTable.get("symbol")); } @Test public void redefineSymbolValue() { symbolTable.put("symbol", T); symbolTable.put("symbol", NIL); assertEquals(NIL, symbolTable.get("symbol")); } @Test public void checkParentTableIsCorrect() { SymbolTable childTable = new SymbolTable(symbolTable); assertEquals(symbolTable, childTable.getParent()); } @Test public void lookupSymbolInParentTable() { symbolTable.put("symbol", T); SymbolTable childTable = new SymbolTable(symbolTable); SymbolTable parentTable = childTable.getParent(); assertEquals(T, parentTable.get("symbol")); } }