Exemplo n.º 1
0
 def setup_class(cls):
     cls.G = nx.path_graph(9)
     cls.DG = nx.path_graph(9, create_using=nx.DiGraph())
     cls.Gv = nx.to_undirected(cls.DG)
     cls.DGv = nx.to_directed(cls.G)
     cls.Rv = cls.DG.reverse()
     cls.graphs = [cls.G, cls.DG, cls.Gv, cls.DGv, cls.Rv]
     for G in cls.graphs:
         G.edges, G.nodes, G.degree
Exemplo n.º 2
0
 def test_path(self):
     G = nx.path_graph(10)
     assert list(nx.clustering(G, weight="weight").values()) == [
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
     ]
     assert nx.clustering(G, weight="weight") == {
         0: 0.0,
         1: 0.0,
         2: 0.0,
         3: 0.0,
         4: 0.0,
         5: 0.0,
         6: 0.0,
         7: 0.0,
         8: 0.0,
         9: 0.0,
     }
Exemplo n.º 3
0
 def test_path(self):
     G = nx.path_graph(10)
     assert list(nx.square_clustering(G).values()) == [
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
     ]
     assert nx.square_clustering(G) == {
         0: 0.0,
         1: 0.0,
         2: 0.0,
         3: 0.0,
         4: 0.0,
         5: 0.0,
         6: 0.0,
         7: 0.0,
         8: 0.0,
         9: 0.0,
     }
Exemplo n.º 4
0
 def test_path(self):
     G = nx.path_graph(10, create_using=nx.DiGraph())
     assert list(nx.clustering(G).values()) == [
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
         0.0,
     ]
     assert nx.clustering(G) == {
         0: 0.0,
         1: 0.0,
         2: 0.0,
         3: 0.0,
         4: 0.0,
         5: 0.0,
         6: 0.0,
         7: 0.0,
         8: 0.0,
         9: 0.0,
     }
Exemplo n.º 5
0
 def test_P3_unweighted(self):
     """Eigenvector centrality: P3"""
     G = nx.path_graph(3)
     b_answer = {0: 0.5, 1: 0.7071, 2: 0.5}
     b = nx.eigenvector_centrality_numpy(G, weight=None)
     for n in sorted(G):
         assert almost_equal(b[n], b_answer[n], places=4)
Exemplo n.º 6
0
 def test_maxiter(self):
     with pytest.raises(nx.PowerIterationFailedConvergence):
         alpha = 0.1
         G = nx.path_graph(3)
         max_iter = 0
         try:
             b = nx.katz_centrality(G, alpha, max_iter=max_iter)
         except nx.NetworkXError as e:
             assert str(
                 max_iter) in e.args[0], "max_iter value not in error msg"
             raise  # So that the decorater sees the exception.
Exemplo n.º 7
0
 def test_beta_as_dict(self):
     alpha = 0.1
     beta = {0: 1.0, 1: 1.0, 2: 1.0}
     b_answer = {
         0: 0.5598852584152165,
         1: 0.6107839182711449,
         2: 0.5598852584152162
     }
     G = nx.path_graph(3)
     b = nx.katz_centrality(G, alpha, beta)
     for n in sorted(G):
         assert almost_equal(b[n], b_answer[n], places=4)
Exemplo n.º 8
0
 def setup_method(self):
     # Create a path graph on five nodes.
     G = nx.path_graph(5)
     # Add some node, edge, and graph attributes.
     for i in range(5):
         G.nodes[i]["name"] = "node{}".format(i)
     G.edges[0, 1]["name"] = "edge01"
     G.edges[3, 4]["name"] = "edge34"
     G.graph["name"] = "graph"
     # Get the subgraph induced by the first and last edges.
     self.G = G
     self.H = G.edge_subgraph([(0, 1), (3, 4)])
Exemplo n.º 9
0
 def test_P3(self):
     """Katz centrality: P3"""
     alpha = 0.1
     G = nx.path_graph(3)
     b_answer = {
         0: 0.5598852584152165,
         1: 0.6107839182711449,
         2: 0.5598852584152162
     }
     b = nx.katz_centrality(G, alpha)
     for n in sorted(G):
         assert almost_equal(b[n], b_answer[n], places=4)
Exemplo n.º 10
0
 def test_path(self):
     G = nx.path_graph(10)
     assert list(nx.triangles(G).values()) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
     assert nx.triangles(G) == {
         0: 0,
         1: 0,
         2: 0,
         3: 0,
         4: 0,
         5: 0,
         6: 0,
         7: 0,
         8: 0,
         9: 0,
     }
Exemplo n.º 11
0
    def test_is_at_free(self):
        is_at_free = nx.asteroidal.is_at_free

        cycle = nx.cycle_graph(6)
        assert not is_at_free(cycle)

        path = nx.path_graph(6)
        assert is_at_free(path)

        small_graph = nx.complete_graph(2)
        assert is_at_free(small_graph)

        petersen = nx.petersen_graph()
        assert not is_at_free(petersen)

        clique = nx.complete_graph(6)
        assert is_at_free(clique)
Exemplo n.º 12
0
 def test_multiple_alpha(self):
     alpha_list = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]
     for alpha in alpha_list:
         b_answer = {
             0.1: {
                 0: 0.5598852584152165,
                 1: 0.6107839182711449,
                 2: 0.5598852584152162,
             },
             0.2: {
                 0: 0.5454545454545454,
                 1: 0.6363636363636365,
                 2: 0.5454545454545454,
             },
             0.3: {
                 0: 0.5333964609104419,
                 1: 0.6564879518897746,
                 2: 0.5333964609104419,
             },
             0.4: {
                 0: 0.5232045649263551,
                 1: 0.6726915834767423,
                 2: 0.5232045649263551,
             },
             0.5: {
                 0: 0.5144957746691622,
                 1: 0.6859943117075809,
                 2: 0.5144957746691622,
             },
             0.6: {
                 0: 0.5069794004195823,
                 1: 0.6970966755769258,
                 2: 0.5069794004195823,
             },
         }
         G = nx.path_graph(3)
         b = nx.katz_centrality_numpy(G, alpha)
         for n in sorted(G):
             assert almost_equal(b[n], b_answer[alpha][n], places=4)
Exemplo n.º 13
0
    def setup_method(self):
        # self.K = nx.krackhardt_kite_graph()
        self.P3 = nx.path_graph(3)
        self.K5 = nx.complete_graph(5)

        # F = nx.Graph()  # Florentine families
        # F.add_edge('Acciaiuoli', 'Medici')
        # F.add_edge('Castellani', 'Peruzzi')
        # F.add_edge('Castellani', 'Strozzi')
        # F.add_edge('Castellani', 'Barbadori')
        # F.add_edge('Medici', 'Barbadori')
        # F.add_edge('Medici', 'Ridolfi')
        # F.add_edge('Medici', 'Tornabuoni')
        # F.add_edge('Medici', 'Albizzi')
        # F.add_edge('Medici', 'Salviati')
        # F.add_edge('Salviati', 'Pazzi')
        # F.add_edge('Peruzzi', 'Strozzi')
        # F.add_edge('Peruzzi', 'Bischeri')
        # F.add_edge('Strozzi', 'Ridolfi')
        # F.add_edge('Strozzi', 'Bischeri')
        # F.add_edge('Ridolfi', 'Tornabuoni')
        # F.add_edge('Tornabuoni', 'Guadagni')
        # F.add_edge('Albizzi', 'Ginori')
        # F.add_edge('Albizzi', 'Guadagni')
        # F.add_edge('Bischeri', 'Guadagni')
        # F.add_edge('Guadagni', 'Lamberteschi')
        # self.F = F

        G = nx.DiGraph()
        G.add_edge(0, 5)
        G.add_edge(1, 5)
        G.add_edge(2, 5)
        G.add_edge(3, 5)
        G.add_edge(4, 5)
        G.add_edge(5, 6)
        G.add_edge(5, 7)
        G.add_edge(5, 8)
        self.G = G
Exemplo n.º 14
0
 def setup_method(self):
     self.G = nx.path_graph(10)
Exemplo n.º 15
0
 def test_path(self):
     G = nx.path_graph(10)
     assert nx.transitivity(G) == 0.0
Exemplo n.º 16
0
 def setup_method(self):
     self.DG = nx.path_graph(9, create_using=nx.DiGraph())
     self.uv = nx.to_undirected(self.DG)
Exemplo n.º 17
0
 def setup_method(self):
     self.G = nx.path_graph(9)
     self.dv = nx.to_directed(self.G)
Exemplo n.º 18
0
 def test_path(self):
     G = nx.path_graph(5)
     assert nx.generalized_degree(G, 0) == {0: 1}
     assert nx.generalized_degree(G, 1) == {0: 2}
Exemplo n.º 19
0
 def test_graphs_not_equal2(self):
     G = nx.path_graph(4)
     H = nx.Graph()
     nx.add_path(H, range(3))
     self._test_not_equal(G, H)
Exemplo n.º 20
0
 def test_multidigraphs_equal(self):
     G = nx.path_graph(4, create_using=nx.MultiDiGraph())
     H = nx.MultiDiGraph()
     nx.add_path(H, range(4))
     self._test_equal(G, H)
Exemplo n.º 21
0
 def setup_method(cls):
     cls.P4 = nx.path_graph(4)
     cls.D = nx.DiGraph()
     cls.D.add_edges_from([(0, 2), (0, 3), (1, 3), (2, 3)])
     cls.S = nx.Graph()
     cls.S.add_edges_from([(0, 0), (1, 1)])
Exemplo n.º 22
0
 def test_run_kcore(self, graphscope_session):
     G = nx.path_graph(5)
     nx.builtin.k_core(G, k=2)
Exemplo n.º 23
0
 def test_graphs_not_equal(self):
     G = nx.path_graph(4)
     H = nx.Graph()
     nx.add_cycle(H, range(4))
     self._test_not_equal(G, H)
Exemplo n.º 24
0
 def test_maxiter(self):
     with pytest.raises(nx.PowerIterationFailedConvergence):
         G = nx.path_graph(3)
         b = nx.eigenvector_centrality(G, max_iter=0)
Exemplo n.º 25
0
 def test_graphs_not_equal3(self):
     G = nx.path_graph(4)
     H = nx.Graph()
     nx.add_path(H, range(4))
     H.name = "path_graph(4)"
     self._test_not_equal(G, H)
Exemplo n.º 26
0
 def setup_method(self):
     self.G = nx.path_graph(9, create_using=nx.DiGraph())
     self.rv = nx.reverse_view(self.G)