def test_del_vertex(self): d = DirectedGraph({1: [2, 3], 2: [4], 3: [4]}) self.assertEqual(d.get_outdegree(1), 2) self.assertEqual(d.get_indegree(4), 2) self.assertEqual(len(d), 4) self.assertTrue(2 in d) d.del_vertex(2) self.assertEqual(d.get_outdegree(1), 1) self.assertEqual(d.get_indegree(4), 1) self.assertEqual(len(d), 3) self.assertFalse(2 in d)
def test_del_vertex(): graph = DirectedGraph({1: [2, 3], 2: [4], 3: [4]}) assert graph.get_outdegree(1) == 2 assert graph.get_indegree(4) == 2 assert len(graph) == 4 assert 2 in graph graph.del_vertex(2) assert graph.get_outdegree(1) == 1 assert graph.get_indegree(4) == 1 assert len(graph) == 3 assert 2 not in graph
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)
def test_add_vertex(self): d = DirectedGraph({1: [2, 3], 2: [4], 3: [4]}) d.add_vertex(5) self.assertTrue(5 in d) self.assertEqual(d.get_indegree(5), 0) self.assertEqual(d.get_outdegree(5), 0) self.assertEqual(d[5], [])
def test_add_vertex(): graph = DirectedGraph({1: [2, 3], 2: [4], 3: [4]}) graph.add_vertex(5) assert 5 in graph assert graph.get_indegree(5) == 0 assert graph.get_outdegree(5) == 0 assert graph.get_neighbors(5) == []
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