This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
sp-04/test/ch/usi/inf/sp/dom/DominatorTreeTest.java

41 lines
1.2 KiB
Java
Raw Normal View History

2023-10-18 19:57:49 +00:00
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));
}
}