def test_detect_no_cycles(self): self.assertEqual(self.G.v(), self.N) algorithm = AcyclicGraphDFS(self.G) algorithm.run(1) # it is safe, because G is connected parent_expected = {1: None, 0: 1, 3: 6, 2: 5, 5: 1, 4: 0, 7: 6, 6: 2} self.assertEqual(algorithm.parent, parent_expected) self.assertTrue(is_acyclic(self.G))
def test_detect_no_directed_cycles(self): self.assertEqual(self.G.v(), self.N) algorithm = AcyclicGraphDFS(self.G) algorithm.run(0) # in order to easy test parent_expected = {0: None, 2: 1, 1: 0, 4: 0, 3: 2, 6: 5, 5: 4, 7: 5} #parent_expected = {0: None, 2: 1, 1: 0, 4: 0, 3: 2, 6: 5, 5: 4, 7: 0} self.assertEqual(algorithm.parent, parent_expected) self.assertTrue(is_acyclic(self.G))
def test_detect_cycle3(self): self.assertEqual(self.G.v(), self.N) self.G.add_edge(self.cycle_edges[2]) algorithm = AcyclicGraphDFS(self.G) self.assertRaises(ValueError, algorithm.run) self.assertFalse(is_acyclic(self.G))