def testComputePredecessors(self): # n7 n6 # ^ ^ # | | # | | # n1 ---> n20 --> n3 --> n5 -+ # | ^ ^ | # | | | | # | +------------|---+ # v | # n4 ------------+ n1 = self.prog.NewCFGNode("n1") n20 = n1.ConnectNew("n20") n3 = n20.ConnectNew("n3") n4 = n20.ConnectNew("n4") n5 = n3.ConnectNew("n5") n6 = n20.ConnectNew("n6") n7 = n1.ConnectNew("n7") n3.ConnectTo(n5) n4.ConnectTo(n5) n5.ConnectTo(n20) nodes = [n1, n20, n3, n4, n5, n6, n7] r = utils.compute_predecessors(nodes) self.assertItemsEqual(r[n1], {n1}) self.assertItemsEqual(r[n20], {n1, n20, n3, n4, n5}) self.assertItemsEqual(r[n3], {n1, n20, n3, n4, n5}) self.assertItemsEqual(r[n4], {n1, n20, n3, n4, n5}) self.assertItemsEqual(r[n5], {n1, n20, n3, n4, n5}) self.assertItemsEqual(r[n6], {n1, n20, n3, n4, n5, n6}) self.assertItemsEqual(r[n7], {n1, n7})
def testComputePredecessors(self): # n7 n6 # ^ ^ # | | # | | # n1 ---> n20 --> n3 --> n5 -+ # | ^ ^ | # | | | | # | +------------|---+ # v | # n4 ------------+ n1 = self.prog.NewCFGNode("n1") n20 = n1.ConnectNew("n20") n3 = n20.ConnectNew("n3") n4 = n20.ConnectNew("n4") n5 = n3.ConnectNew("n5") n6 = n20.ConnectNew("n6") n7 = n1.ConnectNew("n7") n3.ConnectTo(n5) n4.ConnectTo(n5) n5.ConnectTo(n20) # Intentionally pick a non-root as nodes[0] to verify that the graph # will still be fully explored. nodes = [n7, n1, n20, n3, n4, n5, n6] r = utils.compute_predecessors(nodes) self.assertItemsEqual(r[n1], {n1}) self.assertItemsEqual(r[n20], {n1, n20, n3, n4, n5}) self.assertItemsEqual(r[n3], {n1, n20, n3, n4, n5}) self.assertItemsEqual(r[n4], {n1, n20, n3, n4, n5}) self.assertItemsEqual(r[n5], {n1, n20, n3, n4, n5}) self.assertItemsEqual(r[n6], {n1, n20, n3, n4, n5, n6}) self.assertItemsEqual(r[n7], {n1, n7})
def testComputePredecessors(self): # n7 n6 # ^ ^ # | | # | | # n1 ---> n20 --> n3 --> n5 -+ # | ^ ^ | # | | | | # | +------------|---+ # v | # n4 ------------+ n1 = self.prog.NewCFGNode("n1") n20 = n1.ConnectNew("n20") n3 = n20.ConnectNew("n3") n4 = n20.ConnectNew("n4") n5 = n3.ConnectNew("n5") n6 = n20.ConnectNew("n6") n7 = n1.ConnectNew("n7") n3.ConnectTo(n5) n4.ConnectTo(n5) n5.ConnectTo(n20) nodes = [n1, n20, n3, n4, n5, n6, n7] r = utils.compute_predecessors(nodes) self.assertItemsEqual(r[n1], {n1}) self.assertItemsEqual(r[n20], {n1, n20, n3, n4, n5}) self.assertItemsEqual(r[n3], {n1, n20, n3, n4, n5}) self.assertItemsEqual(r[n4], {n1, n20, n3, n4, n5}) self.assertItemsEqual(r[n5], {n1, n20, n3, n4, n5}) self.assertItemsEqual(r[n6], {n1, n20, n3, n4, n5, n6}) self.assertItemsEqual(r[n7], {n1, n7})