def test_adjacent_in_directed_graphs(self): g = Graph(True) g.add_edge((1, 2)) self.assertTrue(g.adjacent(1, 2), 'should find them adjacent') self.assertFalse(g.adjacent(2, 1), 'the edge is pointing the other way')
def test_clone(self): g1 = Graph(False) g1.add_edge((1,2,10)) g1.add_edge((2,3,20)) g1.add_edge((3,1,30)) g2 = g1.clone() g2.set_edge_value((1,2), 100) self.assertEqual(g1.get_edge_value((1,2)), 10, 'should not have modified the value of the edge in g1') g2.add_vertex((3,4,40)) self.assertFalse(g1.adjacent(3,4), 'g1 should not have vertex 4')
def test_clone(self): g1 = Graph(False) g1.add_edge((1, 2, 10)) g1.add_edge((2, 3, 20)) g1.add_edge((3, 1, 30)) g2 = g1.clone() g2.set_edge_value((1, 2), 100) self.assertEqual( g1.get_edge_value((1, 2)), 10, 'should not have modified the value of the edge in g1') g2.add_vertex((3, 4, 40)) self.assertFalse(g1.adjacent(3, 4), 'g1 should not have vertex 4')
def test_adjacent_in_directed_graphs(self): g = Graph(True) g.add_edge((1,2)) self.assertTrue(g.adjacent(1,2), 'should find them adjacent') self.assertFalse(g.adjacent(2,1), 'the edge is pointing the other way')
def test_adjacent_in_undirected_graphs(self): g = Graph(False) g.add_edge((1,2)) self.assertTrue(g.adjacent(1,2), 'should find them adjacent') self.assertTrue(g.adjacent(2,1), 'un-directed graph')
def test_adjacent_in_undirected_graphs(self): g = Graph(False) g.add_edge((1, 2)) self.assertTrue(g.adjacent(1, 2), 'should find them adjacent') self.assertTrue(g.adjacent(2, 1), 'un-directed graph')