41 lines
No EOL
1.2 KiB
Java
41 lines
No EOL
1.2 KiB
Java
package ch.usi.inf.sp.dom;
|
|
|
|
import ch.usi.inf.sp.cfg.BasicBlock;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
class DominatorTreeTest {
|
|
|
|
@Test
|
|
void newDominatorTree() {
|
|
DominatorTree t = new DominatorTree();
|
|
assertNull(t.getRoot());
|
|
assertEquals(0, t.getNodes().size());
|
|
assertEquals(0, t.getEdges().size());
|
|
}
|
|
|
|
@Test
|
|
void setRoot() {
|
|
DominatorTree t = new DominatorTree();
|
|
BasicBlock b = new BasicBlock(0);
|
|
t.setRootBlock(b);
|
|
assertSame(b, t.getRoot().getBlock());
|
|
assertEquals(1, t.getNodes().size());
|
|
assertSame(b, t.getNodes().get(0).getBlock());
|
|
assertEquals(0, t.getEdges().size());
|
|
}
|
|
|
|
@Test
|
|
void addDominanceEdge() {
|
|
DominatorTree t = new DominatorTree();
|
|
BasicBlock rootBlock = new BasicBlock(1);
|
|
BasicBlock childBlock = new BasicBlock(2);
|
|
t.setRootBlock(rootBlock);
|
|
DominanceEdge edge = t.addDominanceEdge(rootBlock, childBlock);
|
|
assertSame(rootBlock, t.getRoot().getBlock());
|
|
assertEquals(1, t.getRoot().getOutEdges().size());
|
|
assertSame(edge, t.getRoot().getOutEdges().get(0));
|
|
}
|
|
|
|
} |