def test_topo(self): self.assertEqual(self.graph.is_dag(), False) self.graph.del_edge((3, 1)) self.assertEqual(self.graph.topological_order(), [1, 2, 3]) graph = DirectedGraph() graph.add_edge((1, 2)) graph.add_edge((1, 3)) graph.add_edge((2, 4)) graph.add_edge((3, 4)) self.assertEqual(self.graph.is_dag(), True)
class TestDirectedGarph(unittest.TestCase): """ This is the test case for the directed graph """ def setUp(self): self.graph = DirectedGraph() self.graph.add_edge((1, 2)) self.graph.add_edge((2, 3)) self.graph.add_edge((3, 1)) def test_vertices(self): self.assertEqual(self.graph.vertices, set([1, 2, 3])) def test_edges(self): self.assertEqual(set(self.graph.edges), set([(1, 2), (2, 3), (3, 1)])) def test_predecessor(self): self.assertEqual(self.graph.predecessors(1), [3]) self.assertEqual(self.graph.predecessors(2), [1]) self.assertEqual(self.graph.predecessors(3), [2]) def test_successor(self): self.assertEqual(self.graph.successors(1), [2]) self.assertEqual(self.graph.successors(2), [3]) self.assertEqual(self.graph.successors(3), [1]) def test_delete(self): self.assert_(self.graph.del_edge((1, 2))) self.assertEquals(set(self.graph.edges), set([(2, 3), (3, 1)])) def test_inverse(self): self.graph.inv_edge((1, 2)) self.assertEquals(set(self.graph.edges), set([(2, 1), (2, 3), (3, 1)])) def test_topo(self): self.assertEqual(self.graph.is_dag(), False) self.graph.del_edge((3, 1)) self.assertEqual(self.graph.topological_order(), [1, 2, 3]) graph = DirectedGraph() graph.add_edge((1, 2)) graph.add_edge((1, 3)) graph.add_edge((2, 4)) graph.add_edge((3, 4)) self.assertEqual(self.graph.is_dag(), True) def test_moralize(self): graph_2 = UndirectedGraph() graph_2.add_edge((1, 2)) graph_2.add_edge((2, 3)) graph_2.add_edge((3, 1)) self.assertEquals(graph_2, self.graph.get_moral()) self.graph.del_edge((3,1)) self.assertNotEquals(graph_2, self.graph.get_moral()) self.graph.inv_edge((2,3)) self.assertEquals(graph_2, self.graph.get_moral()) def test_srt(self): str(self.graph)
def setUp(self): self.graph = DirectedGraph() self.graph.add_edge((1, 2)) self.graph.add_edge((2, 3)) self.graph.add_edge((3, 1))