Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/algorithms/assortativity/tests/test_pairs.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 import networkx as nx | |
| 2 from .base_test import BaseTestAttributeMixing, BaseTestDegreeMixing | |
| 3 | |
| 4 | |
| 5 class TestAttributeMixingXY(BaseTestAttributeMixing): | |
| 6 def test_node_attribute_xy_undirected(self): | |
| 7 attrxy = sorted(nx.node_attribute_xy(self.G, "fish")) | |
| 8 attrxy_result = sorted( | |
| 9 [ | |
| 10 ("one", "one"), | |
| 11 ("one", "one"), | |
| 12 ("two", "two"), | |
| 13 ("two", "two"), | |
| 14 ("one", "red"), | |
| 15 ("red", "one"), | |
| 16 ("blue", "two"), | |
| 17 ("two", "blue"), | |
| 18 ] | |
| 19 ) | |
| 20 assert attrxy == attrxy_result | |
| 21 | |
| 22 def test_node_attribute_xy_undirected_nodes(self): | |
| 23 attrxy = sorted(nx.node_attribute_xy(self.G, "fish", nodes=["one", "yellow"])) | |
| 24 attrxy_result = sorted([]) | |
| 25 assert attrxy == attrxy_result | |
| 26 | |
| 27 def test_node_attribute_xy_directed(self): | |
| 28 attrxy = sorted(nx.node_attribute_xy(self.D, "fish")) | |
| 29 attrxy_result = sorted( | |
| 30 [("one", "one"), ("two", "two"), ("one", "red"), ("two", "blue")] | |
| 31 ) | |
| 32 assert attrxy == attrxy_result | |
| 33 | |
| 34 def test_node_attribute_xy_multigraph(self): | |
| 35 attrxy = sorted(nx.node_attribute_xy(self.M, "fish")) | |
| 36 attrxy_result = [ | |
| 37 ("one", "one"), | |
| 38 ("one", "one"), | |
| 39 ("one", "one"), | |
| 40 ("one", "one"), | |
| 41 ("two", "two"), | |
| 42 ("two", "two"), | |
| 43 ] | |
| 44 assert attrxy == attrxy_result | |
| 45 | |
| 46 def test_node_attribute_xy_selfloop(self): | |
| 47 attrxy = sorted(nx.node_attribute_xy(self.S, "fish")) | |
| 48 attrxy_result = [("one", "one"), ("two", "two")] | |
| 49 assert attrxy == attrxy_result | |
| 50 | |
| 51 | |
| 52 class TestDegreeMixingXY(BaseTestDegreeMixing): | |
| 53 def test_node_degree_xy_undirected(self): | |
| 54 xy = sorted(nx.node_degree_xy(self.P4)) | |
| 55 xy_result = sorted([(1, 2), (2, 1), (2, 2), (2, 2), (1, 2), (2, 1)]) | |
| 56 assert xy == xy_result | |
| 57 | |
| 58 def test_node_degree_xy_undirected_nodes(self): | |
| 59 xy = sorted(nx.node_degree_xy(self.P4, nodes=[0, 1, -1])) | |
| 60 xy_result = sorted([(1, 2), (2, 1)]) | |
| 61 assert xy == xy_result | |
| 62 | |
| 63 def test_node_degree_xy_directed(self): | |
| 64 xy = sorted(nx.node_degree_xy(self.D)) | |
| 65 xy_result = sorted([(2, 1), (2, 3), (1, 3), (1, 3)]) | |
| 66 assert xy == xy_result | |
| 67 | |
| 68 def test_node_degree_xy_multigraph(self): | |
| 69 xy = sorted(nx.node_degree_xy(self.M)) | |
| 70 xy_result = sorted( | |
| 71 [(2, 3), (2, 3), (3, 2), (3, 2), (2, 3), (3, 2), (1, 2), (2, 1)] | |
| 72 ) | |
| 73 assert xy == xy_result | |
| 74 | |
| 75 def test_node_degree_xy_selfloop(self): | |
| 76 xy = sorted(nx.node_degree_xy(self.S)) | |
| 77 xy_result = sorted([(2, 2), (2, 2)]) | |
| 78 assert xy == xy_result | |
| 79 | |
| 80 def test_node_degree_xy_weighted(self): | |
| 81 G = nx.Graph() | |
| 82 G.add_edge(1, 2, weight=7) | |
| 83 G.add_edge(2, 3, weight=10) | |
| 84 xy = sorted(nx.node_degree_xy(G, weight="weight")) | |
| 85 xy_result = sorted([(7, 17), (17, 10), (17, 7), (10, 17)]) | |
| 86 assert xy == xy_result |
