示例#1
0
    def test_copy(self):
        g1 = DAG.from_dict_of_lists({1: [2], 2: [3, 4], 3: [], 4: [], 5: []})
        g2 = g1.copy()
        g2.add_edges_from([(2, 5), (2, 6)])

        self.assertDictEqual(g1.succ, {1: [2], 2: [3, 4], 3: [], 4: [], 5: []})
        self.assertDictEqual(g1.pred, {1: [], 2: [1], 3: [2], 4: [2], 5: []})
        self.assertListEqual(g1.nodes, [1, 2, 3, 4, 5])

        self.assertDictEqual(g2.succ, {
            1: [2],
            2: [3, 4, 5, 6],
            3: [],
            4: [],
            5: [],
            6: []
        })
        self.assertDictEqual(g2.pred, {
            1: [],
            2: [1],
            3: [2],
            4: [2],
            5: [2],
            6: [2]
        })
        self.assertListEqual(g2.nodes, [1, 2, 3, 4, 5, 6])
示例#2
0
 def test_root(self):
     g = DAG.from_dict_of_lists({1: [2], 2: [3, 4], 3: [], 4: [], 5: []})
     self.assertListEqual(g.root, [1, 5])
示例#3
0
 def test_from_dict_of_lists(self):
     g = DAG.from_dict_of_lists({1: [2], 2: [3, 4], 3: [], 4: [], 5: []})
     self.assertDictEqual(g.pred, {1: [], 2: [1], 3: [2], 4: [2], 5: []})