-
Notifications
You must be signed in to change notification settings - Fork 12
/
tools_test.py
86 lines (70 loc) · 2.69 KB
/
tools_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
import unittest
import networkx as nx
import numpy as np
import tools
class TestTools(unittest.TestCase):
def test_hasher(self):
def make_base():
return {"np": np.zeros([1000, 1000], dtype=int), "int": 42}
params_base = make_base()
params_same_a = make_base()
params_same_a["np"][42, 43] = 1
params_same_b = make_base()
params_same_b["np"][42, 43] = 1
self.assertEqual(
tools.hasher((), params_same_a), tools.hasher((), params_same_b)
)
self.assertEqual(
tools.hasher([params_same_a["np"], params_same_b["np"]], {}),
tools.hasher([params_same_b["np"], params_same_a["np"]], {}),
)
params_diff_np_a = make_base()
params_diff_np_a["np"][42, 43] = 1
params_diff_np_b = make_base()
params_diff_np_b["np"][42, 431] = 1
self.assertNotEqual(
tools.hasher((), params_diff_np_a), tools.hasher((), params_diff_np_b)
)
self.assertNotEqual(
tools.hasher((), params_base), tools.hasher((), params_diff_np_a)
)
self.assertNotEqual(
tools.hasher((), params_base), tools.hasher((), params_diff_np_b)
)
self.assertNotEqual(
tools.hasher([params_diff_np_a["np"]], {}),
tools.hasher([params_diff_np_b["np"]], {}),
)
self.assertNotEqual(
tools.hasher([params_diff_np_a["np"], params_diff_np_b["np"]], {}),
tools.hasher([params_diff_np_b["np"], params_diff_np_a["np"]], {}),
)
self.assertNotEqual(
tools.hasher([params_base["np"]], {}),
tools.hasher([params_diff_np_a["np"]], {}),
)
self.assertNotEqual(
tools.hasher([params_base["np"]], {}),
tools.hasher([params_diff_np_b["np"]], {}),
)
params_diff_int_a = make_base()
params_diff_int_a["int"] = 43
params_diff_int_b = make_base()
params_diff_int_b["int"] = 44
self.assertNotEqual(
tools.hasher((), params_diff_int_a), tools.hasher((), params_diff_int_b)
)
self.assertNotEqual(
tools.hasher((), params_base), tools.hasher((), params_diff_int_a)
)
self.assertNotEqual(
tools.hasher((), params_base), tools.hasher((), params_diff_int_b)
)
def test_graphs(self):
g1 = nx.Graph([(0, 1)])
nx.set_node_attributes(g1, {0: {"pos": [0, 0]}})
g2 = nx.Graph([(0, 1)])
nx.set_node_attributes(g2, {0: {"pos": [0, 0.1]}})
self.assertNotEqual(tools.hasher([g1], {}), tools.hasher([g2], {}))
if __name__ == "__main__": # pragma: no cover
unittest.main()