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
github-classroom[bot] 74a433f602
Initial commit
2023-10-18 19:57:49 +00:00

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));
}
}