Beispiel #1
0
 def setUp(self):
     self.graph_one_node = Graph(np.array([[0]]))
     self.graph_tree_even_diameter = Graph(
         np.array([[0, 1, 1, 1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 1, 1, 1, 0],
                   [1, 0, 0, 0, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0],
                   [0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0],
                   [0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1],
                   [0, 0, 0, 0, 0, 0, 0, 1, 0]]))
     self.graph_tree_odd_diameter = Graph(
         np.array([[0, 0, 1, 1, 0, 0, 0, 0, 0, 1],
                   [0, 0, 0, 0, 0, 1, 1, 1, 0, 1],
                   [1, 0, 0, 0, 1, 0, 0, 0, 0, 0],
                   [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                   [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
                   [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
                   [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
                   [0, 1, 0, 0, 0, 0, 0, 0, 1, 0],
                   [0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
                   [1, 1, 0, 0, 0, 0, 0, 0, 0, 0]]))
     self.graph_not_tree = Graph(
         np.array([[0, 0, 1, 1, 0, 0, 0, 1, 0, 1],
                   [0, 0, 1, 0, 0, 1, 1, 1, 0, 1],
                   [1, 1, 0, 0, 1, 0, 0, 0, 0, 0],
                   [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                   [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
                   [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
                   [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
                   [1, 1, 0, 0, 0, 0, 0, 0, 1, 0],
                   [0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
                   [1, 1, 0, 0, 0, 0, 0, 0, 0, 0]]))
Beispiel #2
0
 def test_valid_3x3_matrix__valid_adj_list(self):
     matrix = np.array([[0, 1, 0],
                        [1, 0, 1],
                        [0, 1, 0]])
     graph = Graph(matrix)
     self.assertEqual(set(graph.adj_list[0]), {1})
     self.assertEqual(set(graph.adj_list[1]), {0, 2})
     self.assertEqual(set(graph.adj_list[2]), {1})
Beispiel #3
0
    def setUp(self):
        self.tree_one_node = Tree(Graph(np.array([[]])))
        self.tree_one_node.root = 0
        self.tree_one_node.adj_list = [[]]

        self.tree_even_diam = Tree(Graph(np.array([[]])))
        self.tree_even_diam.root = -1
        self.tree_even_diam.adj_list = [
            [-1, 2, 3],  # 0
            [-1, 5, 6, 7],  # 1
            [0, 4],  # 2
            [0],  # 3
            [2],  # 4
            [1],  # 5
            [1],  # 6
            [1, 8],  # 7
            [7],  # 8
            [0, 1]  # -1
        ]

        self.tree_odd_diam = Tree(Graph(np.array([[]])))
        self.tree_odd_diam.root = 9
        self.tree_odd_diam.adj_list = [
            [2, 3, 9],  # 0
            [5, 6, 7, 9],  # 1
            [0, 4],  # 2
            [0],  # 3
            [2],  # 4
            [1],  # 5
            [1],  # 6
            [1, 8],  # 7
            [7],  # 8
            [0, 1]  # 9
        ]

        self.not_tree = Tree(Graph(np.array([[]])))
        self.not_tree.root = None
        self.not_tree.adj_list = None
Beispiel #4
0
    def setUp(self):
        self.graph_tree = Graph(np.array([[]]))
        self.graph_unlinked = Graph(np.array([[]]))
        self.graph_loop = Graph(np.array([[]]))
        self.graph_one_node = Graph(np.array([[]]))

        # adjacency matrix of a tree
        self.graph_tree.adj_list = [
            [1, 2],     # 0
            [3, 4, 0],  # 1
            [0, 5],     # 2
            [1, 6],     # 3
            [1],        # 4
            [2],        # 5
            [3]         # 6
        ]
        # adjacency matrix of a graph with loop
        self.graph_unlinked.adj_list = [
            [1, 2],     # 0
            [0],        # 1
            [0, 5],     # 2
            [4, 6],     # 3
            [3],        # 4
            [2],        # 5
            [3]         # 6
        ]
        # adjacency matrix of a graph with loop
        self.graph_loop.adj_list = [
            [1, 2],     # 0
            [0, 3, 4],  # 1
            [0, 3, 5],  # 2
            [1, 4, 6],  # 3
            [1, 3],     # 4
            [2],        # 5
            [3],        # 6
        ]
        # adjacency matrix of a graph with one vertex
        self.graph_one_node.adj_list = [[0]]
Beispiel #5
0
 def test_empty_matrix__empty_adj_list(self):
     matrix = np.array([[]])
     graph = Graph(matrix)
     self.assertTrue(not graph.adj_list)
Beispiel #6
0
 def test_valid_1x1_matrix__valid_adj_list(self):
     matrix = np.array([[0]])
     graph = Graph(matrix)
     self.assertEqual(len(graph.adj_list), 1)
Beispiel #7
0
 def test_not_sym_matrix__empty_adj_list(self):
     matrix = np.array([[0, 1, 0],
                        [1, 0, 0],
                        [1, 0, 1]])
     graph = Graph(matrix)
     self.assertTrue(not graph.adj_list)