Beispiel #1
0
 def should_disconnect_nodes_in_directional_graph(self):
     graph = clckwrkbdgr.math.graph.Graph(directional=True)
     graph.add_node('A')
     graph.add_node('B')
     graph.add_node('C')
     graph.add_node('D')
     graph.connect('A', 'B')
     graph.connect('C', 'A')
     graph.connect('C', 'B')
     graph.connect('B', 'C')
     with self.assertRaises(ValueError):
         graph.disconnect('A', 'X')
     with self.assertRaises(ValueError):
         graph.disconnect('X', 'A')
     with self.assertRaises(ValueError):
         graph.disconnect('A', 'D')
     with self.assertRaises(ValueError):
         graph.disconnect('D', 'A')
     with self.assertRaises(ValueError):
         graph.disconnect('B', 'A')
     graph.disconnect('A', 'B')
     graph.disconnect('C', 'B')
     graph.disconnect('B', 'C')
     self.assertFalse(graph.has_connection('A', 'B'))
     self.assertFalse(graph.has_connection('B', 'A'))
     self.assertFalse(graph.has_connection('B', 'C'))
     self.assertFalse(graph.has_connection('C', 'B'))
     self.assertTrue(graph.has_connection('C', 'A'))
Beispiel #2
0
 def should_remove_node(self):
     graph = clckwrkbdgr.math.graph.Graph()
     graph.add_node('A')
     graph.add_node('B')
     graph.add_node('C')
     graph.connect('A', 'B')
     graph.connect('A', 'C')
     graph.connect('B', 'C')
     with self.assertRaises(ValueError):
         graph.remove_node('X')
     graph.remove_node('A')
     self.assertFalse(graph.has_node('A'))
     self.assertFalse(graph.has_connection('A', 'B'))
     self.assertFalse(graph.has_connection('A', 'C'))
     self.assertTrue(graph.has_connection('B', 'C'))
Beispiel #3
0
 def should_connect_nodes_in_directional_graph(self):
     graph = clckwrkbdgr.math.graph.Graph(directional=True)
     graph.add_node('A')
     graph.add_node('B')
     graph.add_node('C')
     graph.add_node('D')
     with self.assertRaises(ValueError):
         graph.connect('A', 'X')
     with self.assertRaises(ValueError):
         graph.connect('X', 'A')
     graph.connect('A', 'B')
     graph.connect('B', 'C')
     with self.assertRaises(ValueError):
         graph.connect('B', 'C')
     graph.connect('C', 'B')
     self.assertEqual(graph.all_connections('A'), {'B'})
     self.assertEqual(graph.all_connections('B'), {'C'})
     self.assertEqual(graph.all_connections('B', with_incoming=True),
                      {'C', 'A'})
     self.assertEqual(graph.all_connections('D'), set())
     self.assertTrue(graph.has_connection('A', 'B'))
     self.assertFalse(graph.has_connection('B', 'A'))
     self.assertTrue(graph.has_connection('B', 'C'))
     self.assertTrue(graph.has_connection('C', 'B'))
     self.assertFalse(graph.has_connection('A', 'C'))
     self.assertFalse(graph.has_connection('D', 'A'))
     self.assertFalse(graph.has_connection('A', 'D'))