-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,125 @@ | ||
from onion_network import onion_graph_from_degree_sequence | ||
import networkx as nx | ||
import pytest | ||
|
||
|
||
def test_onion_graph_respects_degree(): | ||
degree_sequence = sorted([3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 6, 10]) | ||
@pytest.fixture | ||
def degree_sequence(): | ||
degree_sequence = sorted( | ||
[ | ||
3, | ||
3, | ||
3, | ||
9, | ||
9, | ||
3, | ||
3, | ||
4, | ||
6, | ||
3, | ||
12, | ||
3, | ||
7, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
15, | ||
15, | ||
3, | ||
3, | ||
5, | ||
3, | ||
3, | ||
3, | ||
13, | ||
3, | ||
3, | ||
7, | ||
8, | ||
3, | ||
3, | ||
3, | ||
4, | ||
3, | ||
11, | ||
3, | ||
3, | ||
3, | ||
3, | ||
15, | ||
3, | ||
3, | ||
15, | ||
3, | ||
6, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
15, | ||
3, | ||
3, | ||
5, | ||
3, | ||
12, | ||
3, | ||
8, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
3, | ||
15, | ||
3, | ||
3, | ||
3, | ||
] | ||
) | ||
return degree_sequence | ||
|
||
|
||
def test_onion_graph_respects_degree(degree_sequence): | ||
G = onion_graph_from_degree_sequence(degree_sequence, seed=1) | ||
G_degree = sorted([x for _, x in G.degree()]) | ||
assert all([d1 == d2 for d1, d2 in zip(degree_sequence, G_degree)]) | ||
|
||
|
||
def test_assortativity(degree_sequence): | ||
"""Onion networks should be assortative for alpha big enough: same degree nodes should be connected to similar degree nodes in majority.""" | ||
for i in range(100): | ||
G = onion_graph_from_degree_sequence(degree_sequence, seed=i, alpha=100) | ||
assert nx.degree_assortativity_coefficient(G) > 0 |