-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathra_tests.py
74 lines (60 loc) · 1.35 KB
/
ra_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from ra_network import ra_network
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
def test_1():
"""
Check the number of nodes is correct
"""
n = 10000
m = 4
G = ra_network(n, m)
print("Expected:", n)
print("Measured:", G.number_of_nodes())
def test_2():
"""
Check the number of edges. Note that the
initial graph is complete, so we expect m*n - m(m+1)/2
"""
n = 10000
m = 4
G = ra_network(n, m)
print("Expected:", n*m - int(m*(m+1)/2))
print("Measured:", G.number_of_edges())
def test_3():
"""
Check average degree is 2m
"""
n = 10000
m = 4
G = ra_network(n, m)
print("Expected:", 2*m)
print("Measured:", np.mean([d for _, d in G.degree()]))
def test_4():
"""
Check there are 0 nodes with degree less than m
"""
n = 10000
m = 4
G = ra_network(n, m)
print("Expected: 0")
print("Measured:", sum([d for _, d in G.degree() if d < m]))
def test_5():
"""
Draw the graph, in order to check there are no obvious errors
"""
n = 10
m = 2
G = ra_network(n, m)
nx.draw_networkx(G)
plt.show()
def test_6():
"""
Check invalid m isn't allowed
"""
G = ra_network(10, 0)
def test_7():
"""
Check invalid m and n combinations aren't allowed
"""
G = ra_network(5, 5)