Beispiel #1
0
    def test_random_sample_small(self):
        """Test a graph that is too small to sample."""
        n_nodes, n_edges = 11, 25
        graph = generate_random_graph(n_nodes, n_edges)

        self.assertEqual(n_edges, graph.number_of_edges())

        sg_1 = get_random_subgraph(graph,
                                   number_edges=250,
                                   number_seed_edges=5,
                                   invert_degrees=False)
        self.assertEqual(
            graph.number_of_edges(),
            sg_1.number_of_edges(),
            msg=
            'since graph is too small, the subgraph should contain the whole thing'
        )

        sg_2 = get_random_subgraph(graph,
                                   number_edges=250,
                                   number_seed_edges=5,
                                   invert_degrees=True)
        self.assertEqual(
            graph.number_of_edges(),
            sg_2.number_of_edges(),
            msg=
            'since graph is too small, the subgraph should contain the whole thing'
        )
Beispiel #2
0
    def test_random_sample(self):
        """Test randomly sampling a graph."""
        n_nodes, n_edges = 50, 500
        graph = generate_random_graph(n_nodes=n_nodes, n_edges=n_edges)

        self.assertEqual(n_edges, graph.number_of_edges())

        sg_1 = get_random_subgraph(graph,
                                   number_edges=250,
                                   number_seed_edges=5,
                                   invert_degrees=False)
        self.assertEqual(250, sg_1.number_of_edges())

        sg_2 = get_random_subgraph(graph,
                                   number_edges=250,
                                   number_seed_edges=5,
                                   invert_degrees=True)
        self.assertEqual(250, sg_2.number_of_edges())