Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/generators/tests/test_directed.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 """Generators - Directed Graphs | |
2 ---------------------------- | |
3 """ | |
4 import pytest | |
5 | |
6 import networkx as nx | |
7 from networkx.classes import Graph | |
8 from networkx.classes import MultiDiGraph | |
9 from networkx.generators.directed import gn_graph | |
10 from networkx.generators.directed import gnr_graph | |
11 from networkx.generators.directed import gnc_graph | |
12 from networkx.generators.directed import random_k_out_graph | |
13 from networkx.generators.directed import random_uniform_k_out_graph | |
14 from networkx.generators.directed import scale_free_graph | |
15 | |
16 | |
17 class TestGeneratorsDirected: | |
18 def test_smoke_test_random_graphs(self): | |
19 gn_graph(100) | |
20 gnr_graph(100, 0.5) | |
21 gnc_graph(100) | |
22 scale_free_graph(100) | |
23 | |
24 gn_graph(100, seed=42) | |
25 gnr_graph(100, 0.5, seed=42) | |
26 gnc_graph(100, seed=42) | |
27 scale_free_graph(100, seed=42) | |
28 | |
29 def test_create_using_keyword_arguments(self): | |
30 pytest.raises(nx.NetworkXError, gn_graph, 100, create_using=Graph()) | |
31 pytest.raises(nx.NetworkXError, gnr_graph, 100, 0.5, create_using=Graph()) | |
32 pytest.raises(nx.NetworkXError, gnc_graph, 100, create_using=Graph()) | |
33 pytest.raises(nx.NetworkXError, scale_free_graph, 100, create_using=Graph()) | |
34 G = gn_graph(100, seed=1) | |
35 MG = gn_graph(100, create_using=MultiDiGraph(), seed=1) | |
36 assert sorted(G.edges()) == sorted(MG.edges()) | |
37 G = gnr_graph(100, 0.5, seed=1) | |
38 MG = gnr_graph(100, 0.5, create_using=MultiDiGraph(), seed=1) | |
39 assert sorted(G.edges()) == sorted(MG.edges()) | |
40 G = gnc_graph(100, seed=1) | |
41 MG = gnc_graph(100, create_using=MultiDiGraph(), seed=1) | |
42 assert sorted(G.edges()) == sorted(MG.edges()) | |
43 | |
44 G = scale_free_graph( | |
45 100, | |
46 alpha=0.3, | |
47 beta=0.4, | |
48 gamma=0.3, | |
49 delta_in=0.3, | |
50 delta_out=0.1, | |
51 create_using=MultiDiGraph, | |
52 seed=1, | |
53 ) | |
54 pytest.raises(ValueError, scale_free_graph, 100, 0.5, 0.4, 0.3) | |
55 pytest.raises(ValueError, scale_free_graph, 100, alpha=-0.3) | |
56 pytest.raises(ValueError, scale_free_graph, 100, beta=-0.3) | |
57 pytest.raises(ValueError, scale_free_graph, 100, gamma=-0.3) | |
58 | |
59 | |
60 class TestRandomKOutGraph: | |
61 """Unit tests for the | |
62 :func:`~networkx.generators.directed.random_k_out_graph` function. | |
63 | |
64 """ | |
65 | |
66 def test_regularity(self): | |
67 """Tests that the generated graph is `k`-out-regular.""" | |
68 n = 10 | |
69 k = 3 | |
70 alpha = 1 | |
71 G = random_k_out_graph(n, k, alpha) | |
72 assert all(d == k for v, d in G.out_degree()) | |
73 G = random_k_out_graph(n, k, alpha, seed=42) | |
74 assert all(d == k for v, d in G.out_degree()) | |
75 | |
76 def test_no_self_loops(self): | |
77 """Tests for forbidding self-loops.""" | |
78 n = 10 | |
79 k = 3 | |
80 alpha = 1 | |
81 G = random_k_out_graph(n, k, alpha, self_loops=False) | |
82 assert nx.number_of_selfloops(G) == 0 | |
83 | |
84 | |
85 class TestUniformRandomKOutGraph: | |
86 """Unit tests for the | |
87 :func:`~networkx.generators.directed.random_uniform_k_out_graph` | |
88 function. | |
89 | |
90 """ | |
91 | |
92 def test_regularity(self): | |
93 """Tests that the generated graph is `k`-out-regular.""" | |
94 n = 10 | |
95 k = 3 | |
96 G = random_uniform_k_out_graph(n, k) | |
97 assert all(d == k for v, d in G.out_degree()) | |
98 G = random_uniform_k_out_graph(n, k, seed=42) | |
99 assert all(d == k for v, d in G.out_degree()) | |
100 | |
101 def test_no_self_loops(self): | |
102 """Tests for forbidding self-loops.""" | |
103 n = 10 | |
104 k = 3 | |
105 G = random_uniform_k_out_graph(n, k, self_loops=False) | |
106 assert nx.number_of_selfloops(G) == 0 | |
107 assert all(d == k for v, d in G.out_degree()) | |
108 | |
109 def test_with_replacement(self): | |
110 n = 10 | |
111 k = 3 | |
112 G = random_uniform_k_out_graph(n, k, with_replacement=True) | |
113 assert G.is_multigraph() | |
114 assert all(d == k for v, d in G.out_degree()) | |
115 | |
116 def test_without_replacement(self): | |
117 n = 10 | |
118 k = 3 | |
119 G = random_uniform_k_out_graph(n, k, with_replacement=False) | |
120 assert not G.is_multigraph() | |
121 assert all(d == k for v, d in G.out_degree()) |