2016-12-19 13:29:31 -05:00
|
|
|
package table;
|
|
|
|
|
|
|
|
import static org.junit.Assert.*;
|
2017-03-02 09:54:23 -05:00
|
|
|
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
|
2017-02-06 12:02:19 -05:00
|
|
|
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() {
|
2017-03-02 09:54:23 -05:00
|
|
|
symbolTable.put("symbol", T);
|
2017-02-06 12:02:19 -05:00
|
|
|
|
2016-12-19 13:29:31 -05:00
|
|
|
assertTrue(symbolTable.contains("symbol"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void retrieveSymbolValue() {
|
2017-03-02 09:54:23 -05:00
|
|
|
symbolTable.put("symbol", T);
|
2017-02-06 12:02:19 -05:00
|
|
|
|
2017-03-02 09:54:23 -05:00
|
|
|
assertEquals(T, symbolTable.get("symbol"));
|
2016-12-19 13:29:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void redefineSymbolValue() {
|
2017-03-02 09:54:23 -05:00
|
|
|
symbolTable.put("symbol", T);
|
|
|
|
symbolTable.put("symbol", NIL);
|
2017-02-06 12:02:19 -05:00
|
|
|
|
2017-03-02 09:54:23 -05:00
|
|
|
assertEquals(NIL, 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() {
|
2017-03-02 09:54:23 -05:00
|
|
|
symbolTable.put("symbol", T);
|
2016-12-19 13:29:31 -05:00
|
|
|
SymbolTable childTable = new SymbolTable(symbolTable);
|
|
|
|
SymbolTable parentTable = childTable.getParent();
|
|
|
|
|
2017-03-02 09:54:23 -05:00
|
|
|
assertEquals(T, parentTable.get("symbol"));
|
2016-12-19 13:29:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|