示例#1
0
    def test_vertices(self):
        self.assertEqual(set(self.d1.vertices()), set([1, 2, 3, 4]))

        d2 = DirectedGraph()
        d2.add_edge(1, 2)
        d2.add_edge(2, 3)
        d2.add_edge(3, 4)
        self.assertEqual(set(d2.vertices()), set([1, 2, 3, 4]))
示例#2
0
def test_vertices(test_graph):
    assert test_graph.get_vertices() == set([1, 2, 3, 4])

    graph = DirectedGraph()
    graph.add_edge(1, 2)
    graph.add_edge(2, 3)
    graph.add_edge(3, 4)
    assert graph.get_vertices() == set([1, 2, 3, 4])
示例#3
0
    def test_add_edge(self):
        d = DirectedGraph()
        self.assertFalse(d.is_edge(1, 2))
        self.assertEqual(d.get_outdegree(1), 0)

        d.add_edge(1, 2)

        self.assertEqual(d.get_outdegree(1), 1)
        self.assertEqual(d.get_indegree(2), 1)
        self.assertTrue(d.is_edge(1, 2))

        d.add_edge(1, 2)

        self.assertTrue(1, 2)
        self.assertEqual(d.get_indegree(2), 1)
示例#4
0
def test_add_edge():
    graph = DirectedGraph()
    assert not graph.is_edge(1, 2)
    assert graph.get_outdegree(1) == 0

    graph.add_edge(1, 2)

    assert graph.get_outdegree(1) == 1
    assert graph.get_indegree(2) == 1
    assert graph.is_edge(1, 2)

    graph.add_edge(1, 2)

    assert graph.get_indegree(1) == 0
    assert graph.get_outdegree(1) == 2
    assert graph.get_indegree(2) == 2