-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
141 lines (119 loc) · 3.35 KB
/
test.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import unittest
import graph_isomorphism as gi
from graph_isomorphism import Graph
######## Simplest Example ########
edge_set_graph = Graph([
(0, 1),
(1, 2),
])
edge_set_graph_relabeled = Graph([
('a', 'b'),
('b', 'c'),
])
nodes = set(range(3))
permutations = [
{0: 0, 1: 1, 2: 2},
{0: 0, 1: 2, 2: 1},
{0: 1, 1: 0, 2: 2},
{0: 1, 1: 2, 2: 0},
{0: 2, 1: 0, 2: 1},
{0: 2, 1: 1, 2: 0},
]
homomorphisms = [permutations[0], permutations[-1]]
redundant_graph = Graph([a for a in reversed(edge_set_graph)] + list(edge_set_graph))
node_degree = {1: [0, 2], 2: [1]}
######## Second Example ########
edge_set_graph2 = Graph([
(0, 1),
(1, 2),
(2, 3),
])
node_degree2 = {1: [0, 3], 2: [1, 2]}
node_degree_permutations2 = [
{0: 0, 1: 1, 2: 2, 3: 3},
{0: 0, 1: 2, 2: 1, 3: 3},
{0: 3, 1: 1, 2: 2, 3: 0},
{0: 3, 1: 2, 2: 1, 3: 0},
]
class bq_tests(unittest.TestCase):
def test001_collect_nodes(self):
self.assertEqual(
nodes,
edge_set_graph.nodes()
)
def test002_create_permutations(self):
self.assertEqual(
permutations,
gi.create_permutations(nodes)
)
def test003_permute_graph(self):
self.assertEqual(
((0, 1), (1, 2)),
edge_set_graph.permute(permutations[-1])
)
def test004_cannonize_graph(self):
self.assertEqual(
edge_set_graph,
Graph(redundant_graph)
)
def test005_is_same_graph(self):
# redundant on test004_cannonize_graph
self.assertTrue(
edge_set_graph == redundant_graph
)
self.assertFalse(
edge_set_graph == edge_set_graph[:-1]
)
def test006_find_homomorphisms(self):
self.assertEqual(
homomorphisms,
gi.find_homomorphisms(edge_set_graph, permutations)
)
self.assertEqual(
[node_degree_permutations2[0], node_degree_permutations2[-1]],
gi.find_homomorphisms(edge_set_graph2, node_degree_permutations2)
)
def test007_degree_nodes(self):
self.assertEqual(
node_degree,
edge_set_graph.degree_nodes()
)
self.assertEqual(
node_degree2,
edge_set_graph2.degree_nodes()
)
def test008_node_degree_permutations(self):
self.assertEqual(
homomorphisms,
edge_set_graph.node_degree_permutations()
)
self.assertEqual(
node_degree_permutations2,
edge_set_graph2.node_degree_permutations()
)
def test009_powerset(self):
self.assertEqual(
frozenset([
frozenset({}),
frozenset({1}),
frozenset({0}),
frozenset({0, 1}),
]),
frozenset(gi.powerset(range(2)))
)
self.assertEqual(
frozenset([
frozenset({}),
frozenset({(0, 1)}),
frozenset({(1, 2)}),
frozenset({(0, 1), (1, 2)}),
]),
frozenset(gi.powerset(edge_set_graph))
)
def test010_group_all_graphs_up_to_order(self):
self.assertEqual(
34,
len(gi.extract_graphs_from_grouping(gi.group_all_graphs_up_to_order(5)))
)
if __name__ == '__main__':
unittest.main()