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/DominatorTreeAssertions.java

52 lines
1.6 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 java.util.List;
import static org.junit.jupiter.api.Assertions.*;
/**
* These are static methods used in unit tests to assert properties on DominatorTrees.
*/
public class DominatorTreeAssertions {
public static void assertAllNodesMapToTheirBlocks(DominatorTree t) {
for (DominatorTreeNode n : t.getNodes()) {
assertSame(n, t.getNodeForBlock(n.getBlock()));
}
}
public static void assertNodesHaveCorrectNumberOfParents(DominatorTree t) {
for (DominatorTreeNode node : t.getNodes()) {
if (node==t.getRoot()) {
assertEquals(0, node.getInEdges().size());
} else {
assertEquals(1, node.getInEdges().size());
}
}
}
public static void assertChildrenPointToParent(DominatorTree t) {
for (DominatorTreeNode parent : t.getNodes()) {
for (DominanceEdge e : parent.getOutEdges()) {
DominatorTreeNode child = e.getTo();
assertSame(parent, child.getInEdges().get(0).getFrom());
}
}
}
public static void assertPathToRoot(DominatorTree t, List<BasicBlock> pathToRoot) {
DominatorTreeNode child = null;
for (BasicBlock b: pathToRoot) {
DominatorTreeNode node = t.getNodeForBlock(b);
assertSame(b, node.getBlock());
if (child!=null) {
assertEquals(b, child.getInEdges().get(0).getFrom().getBlock());
}
child = node;
}
}
}