comparison env/lib/python3.9/site-packages/networkx/generators/tests/test_stochastic.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 """Unit tests for the :mod:`networkx.generators.stochastic` module."""
2 import pytest
3 import networkx as nx
4
5
6 class TestStochasticGraph:
7 """Unit tests for the :func:`~networkx.stochastic_graph` function.
8
9 """
10
11 def test_default_weights(self):
12 G = nx.DiGraph()
13 G.add_edge(0, 1)
14 G.add_edge(0, 2)
15 S = nx.stochastic_graph(G)
16 assert nx.is_isomorphic(G, S)
17 assert sorted(S.edges(data=True)) == [
18 (0, 1, {"weight": 0.5}),
19 (0, 2, {"weight": 0.5}),
20 ]
21
22 def test_in_place(self):
23 """Tests for an in-place reweighting of the edges of the graph.
24
25 """
26 G = nx.DiGraph()
27 G.add_edge(0, 1, weight=1)
28 G.add_edge(0, 2, weight=1)
29 nx.stochastic_graph(G, copy=False)
30 assert sorted(G.edges(data=True)) == [
31 (0, 1, {"weight": 0.5}),
32 (0, 2, {"weight": 0.5}),
33 ]
34
35 def test_arbitrary_weights(self):
36 G = nx.DiGraph()
37 G.add_edge(0, 1, weight=1)
38 G.add_edge(0, 2, weight=1)
39 S = nx.stochastic_graph(G)
40 assert sorted(S.edges(data=True)) == [
41 (0, 1, {"weight": 0.5}),
42 (0, 2, {"weight": 0.5}),
43 ]
44
45 def test_multidigraph(self):
46 G = nx.MultiDiGraph()
47 G.add_edges_from([(0, 1), (0, 1), (0, 2), (0, 2)])
48 S = nx.stochastic_graph(G)
49 d = dict(weight=0.25)
50 assert sorted(S.edges(data=True)) == [
51 (0, 1, d),
52 (0, 1, d),
53 (0, 2, d),
54 (0, 2, d),
55 ]
56
57 def test_graph_disallowed(self):
58 with pytest.raises(nx.NetworkXNotImplemented):
59 nx.stochastic_graph(nx.Graph())
60
61 def test_multigraph_disallowed(self):
62 with pytest.raises(nx.NetworkXNotImplemented):
63 nx.stochastic_graph(nx.MultiGraph())