def test_cubical(self): G = nx.cubical_graph() assert list(nx.clustering(G).values()) == [0, 0, 0, 0, 0, 0, 0, 0] assert nx.clustering(G, 1) == 0 assert list(nx.clustering(G, [1, 2]).values()) == [0, 0] assert nx.clustering(G, 1) == 0 assert nx.clustering(G, [1, 2]) == {1: 0, 2: 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, }
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, }
def test_k5(self): G = nx.complete_graph(5, create_using=nx.DiGraph()) assert list(nx.clustering(G, weight="weight").values()) == [1, 1, 1, 1, 1] assert nx.average_clustering(G, weight="weight") == 1 G.remove_edge(1, 2) assert list(nx.clustering(G, weight="weight").values()) == [ 11.0 / 12.0, 1.0, 1.0, 11.0 / 12.0, 11.0 / 12.0, ] assert nx.clustering(G, [1, 4], weight="weight") == {1: 1.0, 4: 11.0 / 12.0} G.remove_edge(2, 1) assert list(nx.clustering(G, weight="weight").values()) == [ 5.0 / 6.0, 1.0, 1.0, 5.0 / 6.0, 5.0 / 6.0, ] assert nx.clustering(G, [1, 4], weight="weight") == { 1: 1.0, 4: 0.83333333333333337, }
def test_k5(self): G = nx.complete_graph(5) assert list(nx.clustering(G).values()) == [1, 1, 1, 1, 1] assert nx.average_clustering(G) == 1 G.remove_edge(1, 2) assert list(nx.clustering(G).values()) == [ 5.0 / 6.0, 1.0, 1.0, 5.0 / 6.0, 5.0 / 6.0, ] assert nx.clustering(G, [1, 4]) == {1: 1.0, 4: 0.83333333333333337}
def test_clustering(self): G = nx.DiGraph() assert list(nx.clustering(G).values()) == [] assert nx.clustering(G) == {}
def test_triangle_and_edge(self): G = nx.cycle_graph(3) G.add_edge(0, 4, weight=2) assert nx.clustering(G)[0] == 1.0 / 3.0 assert nx.clustering(G, weight="weight")[0] == 1.0 / 6.0
def test_clustering(self): G = nx.Graph() assert list(nx.clustering(G, weight="weight").values()) == [] assert nx.clustering(G) == {}
def test_triangle_and_edge(self): G = nx.cycle_graph(3, create_using=nx.DiGraph()) G.add_edge(0, 4, weight=2) assert nx.clustering(G)[0] == 1.0 / 6.0 assert nx.clustering(G, weight="weight")[0] == 1.0 / 12.0