rm CondaPkg environment

This commit is contained in:
ton
2023-04-06 13:53:47 +07:00
parent 0a57ed7884
commit c43d949309
3329 changed files with 5725 additions and 447022 deletions

View File

@@ -6,6 +6,7 @@ Generators - Classic
Unit tests for various classic graph generators in generators/classic.py
"""
import itertools
import typing
import pytest
@@ -288,6 +289,15 @@ class TestGeneratorClassic:
assert not H.is_directed()
assert G is not H
# test for subclasses that also use typing.Protocol. See gh-6243
class Mixin(typing.Protocol):
pass
class MyGraph(Mixin, nx.DiGraph):
pass
G = nx.empty_graph(create_using=MyGraph)
def test_empty_graph(self):
G = nx.empty_graph()
assert nx.number_of_nodes(G) == 0
@@ -543,7 +553,7 @@ class TestGeneratorClassic:
assert v not in G[u]
assert G.nodes[u] == G.nodes[v]
# Across blocks, all vertices should be adjacent.
for (block1, block2) in itertools.combinations(blocks, 2):
for block1, block2 in itertools.combinations(blocks, 2):
for u, v in itertools.product(block1, block2):
assert v in G[u]
assert G.nodes[u] != G.nodes[v]

View File

@@ -87,19 +87,19 @@ class TestConfigurationModel:
nx.configuration_model([1, 2])
def test_directed_configuation_raise_unequal():
def test_directed_configuration_raise_unequal():
with pytest.raises(nx.NetworkXError):
zin = [5, 3, 3, 3, 3, 2, 2, 2, 1, 1]
zout = [5, 3, 3, 3, 3, 2, 2, 2, 1, 2]
nx.directed_configuration_model(zin, zout)
def test_directed_configuation_model():
def test_directed_configuration_model():
G = nx.directed_configuration_model([], [], seed=0)
assert len(G) == 0
def test_simple_directed_configuation_model():
def test_simple_directed_configuration_model():
G = nx.directed_configuration_model([1, 1], [1, 1], seed=0)
assert len(G) == 2
@@ -169,11 +169,11 @@ def test_directed_havel_hakimi():
p = 1.0 / r
for i in range(r):
G1 = nx.erdos_renyi_graph(n, p * (i + 1), None, True)
din1 = list(d for n, d in G1.in_degree())
dout1 = list(d for n, d in G1.out_degree())
din1 = [d for n, d in G1.in_degree()]
dout1 = [d for n, d in G1.out_degree()]
G2 = nx.directed_havel_hakimi_graph(din1, dout1)
din2 = list(d for n, d in G2.in_degree())
dout2 = list(d for n, d in G2.out_degree())
din2 = [d for n, d in G2.in_degree()]
dout2 = [d for n, d in G2.out_degree()]
assert sorted(din1) == sorted(din2)
assert sorted(dout1) == sorted(dout2)

View File

@@ -57,6 +57,41 @@ class TestGeneratorsDirected:
pytest.raises(ValueError, scale_free_graph, 100, beta=-0.3)
pytest.raises(ValueError, scale_free_graph, 100, gamma=-0.3)
def test_parameters(self):
G = nx.DiGraph()
G.add_node(0)
def kernel(x):
return x
assert nx.is_isomorphic(gn_graph(1), G)
assert nx.is_isomorphic(gn_graph(1, kernel=kernel), G)
assert nx.is_isomorphic(gnc_graph(1), G)
assert nx.is_isomorphic(gnr_graph(1, 0.5), G)
def test_scale_free_graph_create_using_with_initial_graph():
G = nx.MultiGraph()
with pytest.raises(
ValueError,
match="Cannot set both create_using and initial_graph. Set create_using=None.",
):
scale_free_graph(10, create_using=nx.Graph, initial_graph=G)
def test_scale_free_graph_negative_delta():
with pytest.raises(ValueError, match="delta_in must be >= 0."):
scale_free_graph(10, create_using=None, delta_in=-1)
with pytest.raises(ValueError, match="delta_out must be >= 0."):
scale_free_graph(10, create_using=None, delta_out=-1)
def test_non_numeric_ordering():
G = MultiDiGraph([("a", "b"), ("b", "c"), ("c", "a")])
s = scale_free_graph(3, initial_graph=G)
assert len(s) == 3
assert len(s.edges) == 3
@pytest.mark.parametrize("ig", (nx.Graph(), nx.DiGraph([(0, 1)])))
def test_scale_free_graph_initial_graph_kwarg(ig):
@@ -88,6 +123,10 @@ class TestRandomKOutGraph:
G = random_k_out_graph(n, k, alpha, self_loops=False)
assert nx.number_of_selfloops(G) == 0
def test_negative_alpha(self):
with pytest.raises(ValueError, match="alpha must be positive"):
random_k_out_graph(10, 3, -1)
class TestUniformRandomKOutGraph:
"""Unit tests for the
@@ -119,6 +158,11 @@ class TestUniformRandomKOutGraph:
G = random_uniform_k_out_graph(n, k, with_replacement=True)
assert G.is_multigraph()
assert all(d == k for v, d in G.out_degree())
n = 10
k = 9
G = random_uniform_k_out_graph(n, k, with_replacement=False, self_loops=False)
assert nx.number_of_selfloops(G) == 0
assert all(d == k for v, d in G.out_degree())
def test_without_replacement(self):
n = 10

View File

@@ -60,7 +60,7 @@ def test_paley_graph(p):
# If p = 1 mod 4, -1 is a square mod 4 and therefore the
# edge in the Paley graph are symmetric.
if p % 4 == 1:
for (u, v) in G.edges:
for u, v in G.edges:
assert (v, u) in G.edges

View File

@@ -101,6 +101,7 @@ class TestSoftRandomGeometricGraph:
generator.
"""
# Use the L1 metric.
def dist(x, y):
return sum(abs(a - b) for a, b in zip(x, y))
@@ -287,6 +288,7 @@ class TestThresholdedRandomGeometricGraph:
generator.
"""
# Use the L1 metric.
def dist(x, y):
return sum(abs(a - b) for a, b in zip(x, y))

View File

@@ -16,7 +16,7 @@ class TestHararyGraph:
def test_hnm_harary_graph(self):
# When d is even and r = 0, the hnm_harary_graph(n,m) is
# the circulant_graph(n, list(range(1,d/2+1)))
for (n, m) in [(5, 5), (6, 12), (7, 14)]:
for n, m in [(5, 5), (6, 12), (7, 14)]:
G1 = hnm_harary_graph(n, m)
d = 2 * m // n
G2 = nx.circulant_graph(n, list(range(1, d // 2 + 1)))
@@ -25,7 +25,7 @@ class TestHararyGraph:
# When d is even and r > 0, the hnm_harary_graph(n,m) is
# the circulant_graph(n, list(range(1,d/2+1)))
# with r edges added arbitrarily
for (n, m) in [(5, 7), (6, 13), (7, 16)]:
for n, m in [(5, 7), (6, 13), (7, 16)]:
G1 = hnm_harary_graph(n, m)
d = 2 * m // n
G2 = nx.circulant_graph(n, list(range(1, d // 2 + 1)))
@@ -34,7 +34,7 @@ class TestHararyGraph:
# When d is odd and n is even and r = 0, the hnm_harary_graph(n,m)
# is the circulant_graph(n, list(range(1,(d+1)/2) plus [n//2])
for (n, m) in [(6, 9), (8, 12), (10, 15)]:
for n, m in [(6, 9), (8, 12), (10, 15)]:
G1 = hnm_harary_graph(n, m)
d = 2 * m // n
L = list(range(1, (d + 1) // 2))
@@ -45,7 +45,7 @@ class TestHararyGraph:
# When d is odd and n is even and r > 0, the hnm_harary_graph(n,m)
# is the circulant_graph(n, list(range(1,(d+1)/2) plus [n//2])
# with r edges added arbitrarily
for (n, m) in [(6, 10), (8, 13), (10, 17)]:
for n, m in [(6, 10), (8, 13), (10, 17)]:
G1 = hnm_harary_graph(n, m)
d = 2 * m // n
L = list(range(1, (d + 1) // 2))
@@ -57,7 +57,7 @@ class TestHararyGraph:
# When d is odd and n is odd, the hnm_harary_graph(n,m) is
# the circulant_graph(n, list(range(1,(d+1)/2))
# with m - n*(d-1)/2 edges added arbitrarily
for (n, m) in [(5, 4), (7, 12), (9, 14)]:
for n, m in [(5, 4), (7, 12), (9, 14)]:
G1 = hnm_harary_graph(n, m)
d = 2 * m // n
L = list(range(1, (d + 1) // 2))
@@ -87,21 +87,21 @@ class TestHararyGraph:
def test_hkn_harary_graph(self):
# When k == 1, the hkn_harary_graph(k,n) is
# the path_graph(n)
for (k, n) in [(1, 6), (1, 7)]:
for k, n in [(1, 6), (1, 7)]:
G1 = hkn_harary_graph(k, n)
G2 = nx.path_graph(n)
assert is_isomorphic(G1, G2)
# When k is even, the hkn_harary_graph(k,n) is
# the circulant_graph(n, list(range(1,k/2+1)))
for (k, n) in [(2, 6), (2, 7), (4, 6), (4, 7)]:
for k, n in [(2, 6), (2, 7), (4, 6), (4, 7)]:
G1 = hkn_harary_graph(k, n)
G2 = nx.circulant_graph(n, list(range(1, k // 2 + 1)))
assert is_isomorphic(G1, G2)
# When k is odd and n is even, the hkn_harary_graph(k,n) is
# the circulant_graph(n, list(range(1,(k+1)/2)) plus [n/2])
for (k, n) in [(3, 6), (5, 8), (7, 10)]:
for k, n in [(3, 6), (5, 8), (7, 10)]:
G1 = hkn_harary_graph(k, n)
L = list(range(1, (k + 1) // 2))
L.append(n // 2)
@@ -111,7 +111,7 @@ class TestHararyGraph:
# When k is odd and n is odd, the hkn_harary_graph(k,n) is
# the circulant_graph(n, list(range(1,(k+1)/2))) with
# n//2+1 edges added between node i and node i+n//2+1
for (k, n) in [(3, 5), (5, 9), (7, 11)]:
for k, n in [(3, 5), (5, 9), (7, 11)]:
G1 = hkn_harary_graph(k, n)
G2 = nx.circulant_graph(n, list(range(1, (k + 1) // 2)))
eSet1 = set(G1.edges)

View File

@@ -80,7 +80,6 @@ def test_joint_degree_graph(ntimes=10):
def test_is_valid_directed_joint_degree():
in_degrees = [0, 1, 1, 2]
out_degrees = [1, 1, 1, 1]
nkk = {1: {1: 2, 2: 2}}
@@ -106,7 +105,6 @@ def test_is_valid_directed_joint_degree():
def test_directed_joint_degree_graph(n=15, m=100, ntimes=1000):
for _ in range(ntimes):
# generate gnm random graph and calculate its joint degree.
g = gnm_random_graph(n, m, None, directed=True)

View File

@@ -159,7 +159,7 @@ class TestTriangularLatticeGraph:
G = nx.triangular_lattice_graph(m, n)
N = (n + 1) // 2
assert len(G) == (m + 1) * (1 + N) - (n % 2) * ((m + 1) // 2)
for (i, j) in G.nodes():
for i, j in G.nodes():
nbrs = G[(i, j)]
if i < N:
assert (i + 1, j) in nbrs

View File

@@ -1,7 +1,7 @@
import pytest
import networkx as nx
import networkx.generators.line as line
from networkx.generators import line
from networkx.utils import edges_equal

View File

@@ -65,7 +65,7 @@ def test_gnp_generators_edge_probability(generator, p, directed):
edge_counts = [[0] * n for _ in range(n)]
for i in range(runs):
G = generator(n, p, directed=directed)
for (v, w) in G.edges:
for v, w in G.edges:
edge_counts[v][w] += 1
if not directed:
edge_counts[w][v] += 1
@@ -207,7 +207,6 @@ class TestGeneratorsRandom:
initial_graph = nx.complete_graph(10)
for seed in seeds:
# This should be BA with m = m1
BA1 = nx.barabasi_albert_graph(100, m1, seed)
DBA1 = nx.dual_barabasi_albert_graph(100, m1, m2, 1, seed)

View File

@@ -45,21 +45,21 @@ class TestGeneratorsSmall:
G = nx.chvatal_graph()
assert sorted(G) == list(range(12))
assert G.number_of_edges() == 24
assert list(d for n, d in G.degree()) == 12 * [4]
assert [d for n, d in G.degree()] == 12 * [4]
assert nx.diameter(G) == 2
assert nx.radius(G) == 2
G = nx.cubical_graph()
assert sorted(G) == list(range(8))
assert G.number_of_edges() == 12
assert list(d for n, d in G.degree()) == 8 * [3]
assert [d for n, d in G.degree()] == 8 * [3]
assert nx.diameter(G) == 3
assert nx.radius(G) == 3
G = nx.desargues_graph()
assert sorted(G) == list(range(20))
assert G.number_of_edges() == 30
assert list(d for n, d in G.degree()) == 20 * [3]
assert [d for n, d in G.degree()] == 20 * [3]
G = nx.diamond_graph()
assert sorted(G) == list(range(4))
@@ -70,28 +70,28 @@ class TestGeneratorsSmall:
G = nx.dodecahedral_graph()
assert sorted(G) == list(range(20))
assert G.number_of_edges() == 30
assert list(d for n, d in G.degree()) == 20 * [3]
assert [d for n, d in G.degree()] == 20 * [3]
assert nx.diameter(G) == 5
assert nx.radius(G) == 5
G = nx.frucht_graph()
assert sorted(G) == list(range(12))
assert G.number_of_edges() == 18
assert list(d for n, d in G.degree()) == 12 * [3]
assert [d for n, d in G.degree()] == 12 * [3]
assert nx.diameter(G) == 4
assert nx.radius(G) == 3
G = nx.heawood_graph()
assert sorted(G) == list(range(14))
assert G.number_of_edges() == 21
assert list(d for n, d in G.degree()) == 14 * [3]
assert [d for n, d in G.degree()] == 14 * [3]
assert nx.diameter(G) == 3
assert nx.radius(G) == 3
G = nx.hoffman_singleton_graph()
assert sorted(G) == list(range(50))
assert G.number_of_edges() == 175
assert list(d for n, d in G.degree()) == 50 * [7]
assert [d for n, d in G.degree()] == 50 * [7]
assert nx.diameter(G) == 2
assert nx.radius(G) == 2
@@ -112,7 +112,7 @@ class TestGeneratorsSmall:
G = nx.icosahedral_graph()
assert sorted(G) == list(range(12))
assert G.number_of_edges() == 30
assert list(d for n, d in G.degree()) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
assert [d for n, d in G.degree()] == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
assert nx.diameter(G) == 3
assert nx.radius(G) == 3
@@ -124,26 +124,26 @@ class TestGeneratorsSmall:
G = nx.moebius_kantor_graph()
assert sorted(G) == list(range(16))
assert G.number_of_edges() == 24
assert list(d for n, d in G.degree()) == 16 * [3]
assert [d for n, d in G.degree()] == 16 * [3]
assert nx.diameter(G) == 4
G = nx.octahedral_graph()
assert sorted(G) == list(range(6))
assert G.number_of_edges() == 12
assert list(d for n, d in G.degree()) == 6 * [4]
assert [d for n, d in G.degree()] == 6 * [4]
assert nx.diameter(G) == 2
assert nx.radius(G) == 2
G = nx.pappus_graph()
assert sorted(G) == list(range(18))
assert G.number_of_edges() == 27
assert list(d for n, d in G.degree()) == 18 * [3]
assert [d for n, d in G.degree()] == 18 * [3]
assert nx.diameter(G) == 4
G = nx.petersen_graph()
assert sorted(G) == list(range(10))
assert G.number_of_edges() == 15
assert list(d for n, d in G.degree()) == 10 * [3]
assert [d for n, d in G.degree()] == 10 * [3]
assert nx.diameter(G) == 2
assert nx.radius(G) == 2
@@ -155,24 +155,24 @@ class TestGeneratorsSmall:
G = nx.tetrahedral_graph()
assert sorted(G) == list(range(4))
assert G.number_of_edges() == 6
assert list(d for n, d in G.degree()) == [3, 3, 3, 3]
assert [d for n, d in G.degree()] == [3, 3, 3, 3]
assert nx.diameter(G) == 1
assert nx.radius(G) == 1
G = nx.truncated_cube_graph()
assert sorted(G) == list(range(24))
assert G.number_of_edges() == 36
assert list(d for n, d in G.degree()) == 24 * [3]
assert [d for n, d in G.degree()] == 24 * [3]
G = nx.truncated_tetrahedron_graph()
assert sorted(G) == list(range(12))
assert G.number_of_edges() == 18
assert list(d for n, d in G.degree()) == 12 * [3]
assert [d for n, d in G.degree()] == 12 * [3]
G = nx.tutte_graph()
assert sorted(G) == list(range(46))
assert G.number_of_edges() == 69
assert list(d for n, d in G.degree()) == 46 * [3]
assert [d for n, d in G.degree()] == 46 * [3]
# Test create_using with directed or multigraphs on small graphs
pytest.raises(nx.NetworkXError, nx.tutte_graph, create_using=nx.DiGraph)

View File

@@ -43,7 +43,7 @@ class TestStochasticGraph:
G = nx.MultiDiGraph()
G.add_edges_from([(0, 1), (0, 1), (0, 2), (0, 2)])
S = nx.stochastic_graph(G)
d = dict(weight=0.25)
d = {"weight": 0.25}
assert sorted(S.edges(data=True)) == [
(0, 1, d),
(0, 1, d),