Exemple #1
0
    def test_graph_creation(self):
        generator = graph_util()
        
        for deg in xrange(2, 11, 2):
            for n_side in xrange(2*deg+4,33,7):
                g_p = generator.generate_random_regular_bipartite(n_side, deg)

                g_c_structure = graph.create_graph_structure_test(n_side)
                g_c = graph.create_graph_edges_test(n_side)
                
                # Create the graph in C
                # first n vertices are on left, second n are on right
                for edge in g_p.edges_iter():
                    graph.add_edge(g_c_structure, g_c, edge[0], edge[1])
                    
                # Check that graph in C matches the graph in Python
                for node in xrange(2 * n_side):
                    self.assertEqual(g_p.degree(node), graph.get_degree(g_c, node))
                
                for node in xrange(2 * n_side):
                    if (g_p.degree(node) > 0):
                        self.assertTrue(graph.has_neighbor(g_c, node))

                graph.destroy_graph_structure_test(g_c_structure)
                graph.destroy_graph_edges_test(g_c)
        pass
Exemple #2
0
    def test_keeps_edge_set(self):
        generator = graph_util()
        for deg in xrange(2, 11, 2):
            for n_side in xrange(2 * deg + 4, 33, 7):
                g_p = generator.generate_random_regular_bipartite(n_side, deg)

                # Create the graph in C
                g_c_structure = graph.create_graph_structure_test(n_side)
                g_c = graph.create_graph_edges_test(n_side)
                g_c_copy = graph.create_graph_edges_test(n_side)
                for edge in g_p.edges_iter():
                    graph.add_edge(g_c_structure, g_c, edge[0], edge[1])
                graph.copy_edges(g_c, g_c_copy, n_side)
                self.assertEqual(graph.get_max_degree(g_c, n_side), deg)
                self.assertEqual(graph.get_max_degree(g_c_copy, n_side), deg)

                # Create the output graphs
                g1_c = graph.create_graph_edges_test(n_side)
                g2_c = graph.create_graph_edges_test(n_side)

                eulersplit.split(g_c_structure, g_c_copy, g1_c, g2_c)

                # Check that the input graph is now empty
                self.assertEqual(graph.get_max_degree(g_c_copy, n_side), 0)
                for node in xrange(2 * n_side):
                    self.assertEqual(graph.get_degree(g_c_copy, node), 0)

                # Check that graphs have the correct degree
                self.assertEqual(graph.get_max_degree(g1_c, n_side), deg / 2)
                self.assertEqual(graph.get_max_degree(g2_c, n_side), deg / 2)

                # Check that vertices have the correct degree
                for node in xrange(2 * n_side):
                    self.assertEqual(graph.get_degree(g1_c, node), deg / 2)
                    self.assertEqual(graph.get_degree(g2_c, node), deg / 2)

                # Check that the combination of the two graphs equals the original graph
                graph.add_edges(g1_c, g2_c, n_side)
                self.assertTrue(graph.are_equal(g_c, g1_c, n_side))

                graph.destroy_graph_structure_test(g_c_structure)
                graph.destroy_graph_edges_test(g_c)
                graph.destroy_graph_edges_test(g_c_copy)
                graph.destroy_graph_edges_test(g1_c)
                graph.destroy_graph_edges_test(g2_c)

        pass
    def test_keeps_edge_set(self):
        generator = graph_util()
        for deg in xrange(2, 11, 2):
            for n_side in xrange(2*deg+4,33,7):
                g_p = generator.generate_random_regular_bipartite(n_side, deg)
                
                # Create the graph in C
                g_c_structure = graph.create_graph_structure_test(n_side);
                g_c = graph.create_graph_edges_test(n_side);
                g_c_copy = graph.create_graph_edges_test(n_side)
                for edge in g_p.edges_iter():
                    graph.add_edge(g_c_structure, g_c, edge[0], edge[1])
                graph.copy_edges(g_c, g_c_copy, n_side)
                self.assertEqual(graph.get_max_degree(g_c, n_side), deg)
                self.assertEqual(graph.get_max_degree(g_c_copy, n_side), deg)
 
                # Create the output graphs
                g1_c = graph.create_graph_edges_test(n_side)
                g2_c = graph.create_graph_edges_test(n_side)

                eulersplit.split(g_c_structure, g_c_copy, g1_c, g2_c)

                # Check that the input graph is now empty
                self.assertEqual(graph.get_max_degree(g_c_copy, n_side), 0)
                for node in xrange(2 * n_side):
                    self.assertEqual(graph.get_degree(g_c_copy, node), 0)

                # Check that graphs have the correct degree
                self.assertEqual(graph.get_max_degree(g1_c, n_side), deg / 2)
                self.assertEqual(graph.get_max_degree(g2_c, n_side), deg / 2)

                # Check that vertices have the correct degree
                for node in xrange(2 * n_side):
                    self.assertEqual(graph.get_degree(g1_c, node), deg / 2)
                    self.assertEqual(graph.get_degree(g2_c, node), deg / 2)

                # Check that the combination of the two graphs equals the original graph
                graph.add_edges(g1_c, g2_c, n_side)
                self.assertTrue(graph.are_equal(g_c, g1_c, n_side))
                   
                graph.destroy_graph_structure_test(g_c_structure)
                graph.destroy_graph_edges_test(g_c)
                graph.destroy_graph_edges_test(g_c_copy)
                graph.destroy_graph_edges_test(g1_c)
                graph.destroy_graph_edges_test(g2_c)

        pass