59 lines
1.4 KiB
Java
59 lines
1.4 KiB
Java
package table;
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
import org.junit.*;
|
|
|
|
import sexpression.*;
|
|
|
|
public class SymbolTableTester {
|
|
|
|
private SymbolTable symbolTable;
|
|
|
|
@Before
|
|
public void setUp() throws Exception {
|
|
symbolTable = new SymbolTable();
|
|
}
|
|
|
|
@Test
|
|
public void lookupSymbolNotInTable() {
|
|
assertFalse(symbolTable.contains("symbol"));
|
|
}
|
|
|
|
@Test
|
|
public void lookupSymbolInTable() {
|
|
symbolTable.put("symbol", Symbol.T);
|
|
assertTrue(symbolTable.contains("symbol"));
|
|
}
|
|
|
|
@Test
|
|
public void retrieveSymbolValue() {
|
|
symbolTable.put("symbol", Symbol.T);
|
|
assertEquals(symbolTable.get("symbol"), Symbol.T);
|
|
}
|
|
|
|
@Test
|
|
public void redefineSymbolValue() {
|
|
symbolTable.put("symbol", Symbol.T);
|
|
symbolTable.put("symbol", Nil.getInstance());
|
|
assertEquals(symbolTable.get("symbol"), Nil.getInstance());
|
|
}
|
|
|
|
@Test
|
|
public void checkParentTableIsCorrect() {
|
|
SymbolTable childTable = new SymbolTable(symbolTable);
|
|
|
|
assertEquals(childTable.getParent(), symbolTable);
|
|
}
|
|
|
|
@Test
|
|
public void lookupSymbolInParentTable() {
|
|
symbolTable.put("symbol", Symbol.T);
|
|
SymbolTable childTable = new SymbolTable(symbolTable);
|
|
SymbolTable parentTable = childTable.getParent();
|
|
|
|
assertEquals(parentTable.get("symbol"), Symbol.T);
|
|
}
|
|
|
|
}
|