def test_undirected_graph_connectivity_4(self):
     ''' UndirectedGraph: partial connectivity in 3-node graph with string keys'''
     net = tl.UndirectedGraph()
     net.add_edge('a', 'b')
     net.add_edge('b', 'c')
     self.assertTrue(net.breadth_first_connectivity_search('a', 'b'))
     self.assertTrue(net.breadth_first_connectivity_search('b', 'a'))
     self.assertTrue(net.breadth_first_connectivity_search('a', 'c'))
     self.assertTrue(net.breadth_first_connectivity_search('c', 'a'))
     self.assertTrue(net.breadth_first_connectivity_search('b', 'c'))
     self.assertTrue(net.breadth_first_connectivity_search('c', 'b'))
 def test_undirected_graph_connectivity_3(self):
     ''' UndirectedGraph: no connectivity in 3-node graph with integer keys'''
     net = tl.UndirectedGraph()
     net.add_node(0)
     net.add_node(1)
     net.add_node(2)
     self.assertFalse(net.breadth_first_connectivity_search(0, 1))
     self.assertFalse(net.breadth_first_connectivity_search(1, 0))
     self.assertFalse(net.breadth_first_connectivity_search(0, 2))
     self.assertFalse(net.breadth_first_connectivity_search(2, 0))
     self.assertFalse(net.breadth_first_connectivity_search(1, 2))
     self.assertFalse(net.breadth_first_connectivity_search(2, 1))
     self.assertTrue(net.breadth_first_connectivity_search(0, 0))
     self.assertTrue(net.breadth_first_connectivity_search(1, 1))
     self.assertTrue(net.breadth_first_connectivity_search(2, 2))
    def test_undirected_graph_connectivity_7(self):
        ''' UndirectedGraph: raise exception for checking node not in graph'''
        net = tl.UndirectedGraph()
        net.add_edge('a', 'b')
        net.add_edge('a', 'c')
        self.assertTrue(net.breadth_first_connectivity_search('a', 'b'))
        self.assertTrue(net.breadth_first_connectivity_search('b', 'a'))
        self.assertTrue(net.breadth_first_connectivity_search('a', 'c'))
        self.assertTrue(net.breadth_first_connectivity_search('c', 'a'))
        self.assertTrue(net.breadth_first_connectivity_search('b', 'c'))
        self.assertTrue(net.breadth_first_connectivity_search('c', 'b'))

        for i in range(100):
            with self.assertRaises(tl.NodeExistenceException):
                net.breadth_first_connectivity_search('a',
                                                      np.random.randint(100))
 def test_undirected_graph_connectivity_5(self):
     ''' UndirectedGraph: partially connected 4-node graph with mixed keys'''
     net = tl.UndirectedGraph()
     net.add_edge(0, 'a')
     net.add_edge('a', 1)
     net.add_edge(1, 'b')
     self.assertTrue(net.breadth_first_connectivity_search('a', 'b'))
     self.assertTrue(net.breadth_first_connectivity_search('b', 'a'))
     self.assertTrue(net.breadth_first_connectivity_search(0, 1))
     self.assertTrue(net.breadth_first_connectivity_search(1, 0))
     self.assertTrue(net.breadth_first_connectivity_search(0, 'a'))
     self.assertTrue(net.breadth_first_connectivity_search('a', 0))
     self.assertTrue(net.breadth_first_connectivity_search(0, 'b'))
     self.assertTrue(net.breadth_first_connectivity_search('b', 0))
     self.assertTrue(net.breadth_first_connectivity_search(1, 'a'))
     self.assertTrue(net.breadth_first_connectivity_search('a', 1))
     self.assertTrue(net.breadth_first_connectivity_search(1, 'b'))
     self.assertTrue(net.breadth_first_connectivity_search('b', 1))
    def test_undirected_graph_add_node_1(self):
        ''' UndirectedGraph: ensure that adding a node does not erase previous info '''
        net = tl.UndirectedGraph()
        with self.assertRaises(tl.NodeExistenceException):
            net.breadth_first_connectivity_search('a', 'b')

        net.add_edge('a', 'b')
        net.add_edge('a', 'c')
        self.assertTrue(net.breadth_first_connectivity_search('a', 'b'))
        self.assertTrue(net.breadth_first_connectivity_search('b', 'a'))
        self.assertTrue(net.breadth_first_connectivity_search('a', 'c'))
        self.assertTrue(net.breadth_first_connectivity_search('c', 'a'))
        self.assertTrue(net.breadth_first_connectivity_search('b', 'c'))
        self.assertTrue(net.breadth_first_connectivity_search('c', 'b'))

        net.add_node('a')
        self.assertTrue(net.breadth_first_connectivity_search('a', 'b'))
        self.assertTrue(net.breadth_first_connectivity_search('b', 'a'))
        self.assertTrue(net.breadth_first_connectivity_search('a', 'c'))
        self.assertTrue(net.breadth_first_connectivity_search('c', 'a'))
        self.assertTrue(net.breadth_first_connectivity_search('b', 'c'))
        self.assertTrue(net.breadth_first_connectivity_search('c', 'b'))
 def test_undirected_graph_connectivity_6(self):
     ''' UndirectedGraph: disconnected graphs with mixed keys'''
     net = tl.UndirectedGraph()
     net.add_edge('a', 'b')
     net.add_edge('b', 'c')
     net.add_edge(0, 1)
     net.add_edge(1, 2)
     self.assertTrue(net.breadth_first_connectivity_search('a', 'b'))
     self.assertTrue(net.breadth_first_connectivity_search('b', 'a'))
     self.assertTrue(net.breadth_first_connectivity_search('a', 'c'))
     self.assertTrue(net.breadth_first_connectivity_search('c', 'a'))
     self.assertTrue(net.breadth_first_connectivity_search('b', 'c'))
     self.assertTrue(net.breadth_first_connectivity_search('c', 'b'))
     self.assertTrue(net.breadth_first_connectivity_search(0, 1))
     self.assertTrue(net.breadth_first_connectivity_search(1, 0))
     self.assertTrue(net.breadth_first_connectivity_search(0, 2))
     self.assertTrue(net.breadth_first_connectivity_search(2, 0))
     self.assertTrue(net.breadth_first_connectivity_search(1, 2))
     self.assertTrue(net.breadth_first_connectivity_search(2, 1))
     self.assertFalse(net.breadth_first_connectivity_search(0, 'a'))
     self.assertFalse(net.breadth_first_connectivity_search('a', 0))
     self.assertFalse(net.breadth_first_connectivity_search(0, 'b'))
     self.assertFalse(net.breadth_first_connectivity_search('b', 0))
     self.assertFalse(net.breadth_first_connectivity_search(0, 'c'))
     self.assertFalse(net.breadth_first_connectivity_search('c', 0))
     self.assertFalse(net.breadth_first_connectivity_search(1, 'a'))
     self.assertFalse(net.breadth_first_connectivity_search('a', 1))
     self.assertFalse(net.breadth_first_connectivity_search(1, 'b'))
     self.assertFalse(net.breadth_first_connectivity_search('b', 1))
     self.assertFalse(net.breadth_first_connectivity_search(1, 'c'))
     self.assertFalse(net.breadth_first_connectivity_search('c', 1))
     self.assertFalse(net.breadth_first_connectivity_search(2, 'a'))
     self.assertFalse(net.breadth_first_connectivity_search('a', 2))
     self.assertFalse(net.breadth_first_connectivity_search(2, 'b'))
     self.assertFalse(net.breadth_first_connectivity_search('b', 2))
     self.assertFalse(net.breadth_first_connectivity_search(2, 'c'))
     self.assertFalse(net.breadth_first_connectivity_search('c', 2))