Skip to content

Commit

Permalink
✅ Added test for assortativity.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonPop committed Jun 23, 2023
1 parent 3248b10 commit bb9e752
Showing 1 changed file with 119 additions and 2 deletions.
121 changes: 119 additions & 2 deletions tests/test_generation.py
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

0 comments on commit bb9e752

Please sign in to comment.