2016-12-19 13:29:31 -05:00
|
|
|
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);
|
2017-01-18 16:25:09 -05:00
|
|
|
assertEquals(Symbol.T, symbolTable.get("symbol"));
|
2016-12-19 13:29:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void redefineSymbolValue() {
|
|
|
|
symbolTable.put("symbol", Symbol.T);
|
2016-12-29 13:32:45 -05:00
|
|
|
symbolTable.put("symbol", Nil.getInstance());
|
2017-01-18 16:25:09 -05:00
|
|
|
assertEquals(Nil.getInstance(), symbolTable.get("symbol"));
|
2016-12-19 13:29:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void checkParentTableIsCorrect() {
|
|
|
|
SymbolTable childTable = new SymbolTable(symbolTable);
|
|
|
|
|
2017-01-18 16:25:09 -05:00
|
|
|
assertEquals(symbolTable, childTable.getParent());
|
2016-12-19 13:29:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void lookupSymbolInParentTable() {
|
|
|
|
symbolTable.put("symbol", Symbol.T);
|
|
|
|
SymbolTable childTable = new SymbolTable(symbolTable);
|
|
|
|
SymbolTable parentTable = childTable.getParent();
|
|
|
|
|
2017-01-18 16:25:09 -05:00
|
|
|
assertEquals(Symbol.T, parentTable.get("symbol"));
|
2016-12-19 13:29:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|