def testLevels(self):
        gr = DirectedGraph()
        gr.add_nodes([1, 2, 3, 11, 12, 21, 22, 23, 31])

        gr.add_edge(11, 1)
        gr.add_edge(12, 2)
        gr.add_edge(21, 12)
        gr.add_edge(22, 11)
        gr.add_edge(31, 21)
        gr.add_edge(31, 22)
        gr.add_edge(31, 23)

        self.assertEqual(set([1, 2, 3, 23]), gr.get_levels()[0])
        self.assertEqual(set([11, 12]), gr.get_levels()[1])
        self.assertEqual(set([22, 21]), gr.get_levels()[2])
        self.assertEqual(set([31]), gr.get_levels()[3])

        # cycles no
        self.assertEqual([], gr.get_cycles())

        self.assertEqual(set([1, 2, 11, 12, 21, 22, 23]), gr.compute_closure(31))
        self.assertEqual(set([]), gr.compute_closure(23))
        self.assertEqual(set([1, 11]), gr.compute_closure(22))
        self.assertEqual(set([2, 12]), gr.compute_closure(21))
        self.assertEqual(set([1]), gr.compute_closure(11))
Esempio n. 2
0
    def testLevels(self):
        gr = DirectedGraph()
        gr.add_nodes([1, 2, 3, 11, 12, 21, 22, 23, 31])

        gr.add_edge(11, 1)
        gr.add_edge(12, 2)
        gr.add_edge(21, 12)
        gr.add_edge(22, 11)
        gr.add_edge(31, 21)
        gr.add_edge(31, 22)
        gr.add_edge(31, 23)

        self.assertEqual(set([1, 2, 3, 23]), gr.get_levels()[0])
        self.assertEqual(set([11, 12]), gr.get_levels()[1])
        self.assertEqual(set([22, 21]), gr.get_levels()[2])
        self.assertEqual(set([31]), gr.get_levels()[3])

        # cycles no
        self.assertEqual([], gr.get_cycles())

        self.assertEqual(set([1, 2, 11, 12, 21, 22, 23]),
                         gr.compute_closure(31))
        self.assertEqual(set([]), gr.compute_closure(23))
        self.assertEqual(set([1, 11]), gr.compute_closure(22))
        self.assertEqual(set([2, 12]), gr.compute_closure(21))
        self.assertEqual(set([1]), gr.compute_closure(11))
Esempio n. 3
0
    def testComputeLevels(self):
        g = DirectedGraph()
        for i in range(13):
            g.add_node(BlockName("user/mod%d" % i))

        g.add_edge(BlockName("user/mod0"), BlockName("user/mod2"))
        g.add_edge(BlockName("user/mod0"), BlockName("user/mod3"))
        g.add_edge(BlockName("user/mod0"), BlockName("user/mod4"))
        g.add_edge(BlockName("user/mod3"), BlockName("user/mod6"))
        g.add_edge(BlockName("user/mod4"), BlockName("user/mod7"))
        g.add_edge(BlockName("user/mod6"), BlockName("user/mod9"))
        g.add_edge(BlockName("user/mod7"), BlockName("user/mod9"))
        g.add_edge(BlockName("user/mod9"), BlockName("user/mod12"))

        g.add_edge(BlockName("user/mod1"), BlockName("user/mod5"))
        g.add_edge(BlockName("user/mod5"), BlockName("user/mod8"))
        g.add_edge(BlockName("user/mod8"), BlockName("user/mod10"))
        g.add_edge(BlockName("user/mod8"), BlockName("user/mod11"))

        g.add_edge(BlockName("user/mod10"), BlockName("user/mod12"))
        g.add_edge(BlockName("user/mod7"), BlockName("user/mod10"))

        result = g.get_levels()

        self.assertEquals(5, len(result))
        self.assertEquals(
            result[0],
            set([
                BlockName("user/mod12"),
                BlockName("user/mod11"),
                BlockName("user/mod2")
            ]))

        self.assertEquals(
            result[1], set([BlockName("user/mod9"),
                            BlockName("user/mod10")]))

        self.assertEquals(
            result[2],
            set([
                BlockName("user/mod6"),
                BlockName("user/mod7"),
                BlockName("user/mod8")
            ]))

        self.assertEquals(
            result[3],
            set([
                BlockName("user/mod3"),
                BlockName("user/mod4"),
                BlockName("user/mod5")
            ]))

        self.assertEquals(
            result[4], set([BlockName("user/mod0"),
                            BlockName("user/mod1")]))
    def testComputeLevels(self):
        g = DirectedGraph()
        for i in range(13):
            g.add_node(BlockName("user/mod%d" % i))

        g.add_edge(BlockName("user/mod0"), BlockName("user/mod2"))
        g.add_edge(BlockName("user/mod0"), BlockName("user/mod3"))
        g.add_edge(BlockName("user/mod0"), BlockName("user/mod4"))
        g.add_edge(BlockName("user/mod3"), BlockName("user/mod6"))
        g.add_edge(BlockName("user/mod4"), BlockName("user/mod7"))
        g.add_edge(BlockName("user/mod6"), BlockName("user/mod9"))
        g.add_edge(BlockName("user/mod7"), BlockName("user/mod9"))
        g.add_edge(BlockName("user/mod9"), BlockName("user/mod12"))

        g.add_edge(BlockName("user/mod1"), BlockName("user/mod5"))
        g.add_edge(BlockName("user/mod5"), BlockName("user/mod8"))
        g.add_edge(BlockName("user/mod8"), BlockName("user/mod10"))
        g.add_edge(BlockName("user/mod8"), BlockName("user/mod11"))

        g.add_edge(BlockName("user/mod10"), BlockName("user/mod12"))
        g.add_edge(BlockName("user/mod7"), BlockName("user/mod10"))

        result = g.get_levels()

        self.assertEquals(5, len(result))
        self.assertEquals(result[0], set([BlockName("user/mod12"),
                                          BlockName("user/mod11"),
                                          BlockName("user/mod2")
                                          ]))

        self.assertEquals(result[1], set([BlockName("user/mod9"),
                                          BlockName("user/mod10")]))

        self.assertEquals(result[2], set([BlockName("user/mod6"),
                                          BlockName("user/mod7"),
                                          BlockName("user/mod8")]))

        self.assertEquals(result[3], set([BlockName("user/mod3"),
                                          BlockName("user/mod4"),
                                          BlockName("user/mod5")]))

        self.assertEquals(result[4], set([BlockName("user/mod0"),
                                          BlockName("user/mod1")]))