This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_topo.py
93 lines (56 loc) · 2.04 KB
/
test_topo.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# @Author : FederalLab
# @Date : 2021-09-25 16:56:57
# @Last Modified by : Chen Dengsheng
# @Last Modified time: 2021-09-25 16:56:57
# Copyright (c) FederalLab. All rights reserved.
import openfed
import openfed.topo as topo
def test_node():
alpha = topo.Node('alpha', address=openfed.empty_address)
assert alpha.nick_name == 'alpha'
assert alpha.address == openfed.empty_address
beta = topo.Node('beta', address=openfed.empty_address)
assert alpha != beta
alpha_copy = topo.Node('alpha', address=openfed.empty_address)
assert alpha_copy == alpha
print(alpha)
def test_edge():
alpha = topo.Node('alpha', address=openfed.empty_address)
beta = topo.Node('beta', address=openfed.empty_address)
edge = topo.Edge(alpha, beta)
r_edge = topo.Edge(beta, alpha)
assert edge != r_edge
edge_copy = topo.Edge(alpha, beta)
assert edge_copy == edge
print(edge)
def test_topology():
alpha = topo.Node('alpha', address=openfed.empty_address)
topology = topo.Topology()
topology.add_node(alpha)
topology.add_node('beta', openfed.empty_address)
beta = topology.fetch_node_via_nick_name('beta')
assert beta
edge = topo.Edge(alpha, beta)
topology.add_edge(edge)
topology.add_edge(beta, 'alpha')
print(topology)
topology.remove_edge(0)
topology.remove_node(0)
topology.clear_useless_nodes()
print(topology)
data = topology.serialize()
topology.unserialize(data)
def test_analysis():
topology = topo.Topology()
topology.add_node('alpha', openfed.empty_address)
topology.add_node('beta', openfed.empty_address)
topology.add_node('gamma', openfed.empty_address)
topology.add_edge('alpha', 'beta')
topology.add_edge('beta', 'gamma')
topology.add_edge('gamma', 'alpha')
alpha_fg = topo.analysis(topology, 'alpha')
assert len(alpha_fg) == 2
beta_fg = topo.analysis(topology, 'beta')
assert len(beta_fg) == 2
gamma_fg = topo.analysis(topology, 'gamma')
assert len(gamma_fg) == 2