forked from google-deepmind/alphageometry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph_utils_test.py
145 lines (131 loc) · 4.28 KB
/
graph_utils_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
142
143
144
145
# Copyright 2023 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Unit tests for graph_utils.py."""
import unittest
from absl.testing import absltest
import graph_utils as gu
class GraphUtilsTest(unittest.TestCase):
def test_cross(self):
self.assertEqual(gu.cross([], [1]), [])
self.assertEqual(gu.cross([1], []), [])
self.assertEqual(gu.cross([1], [2]), [(1, 2)])
self.assertEqual(gu.cross([1], [2, 3]), [(1, 2), (1, 3)])
e1 = [1, 2, 3]
e2 = [4, 5]
target = [(1, 4), (1, 5), (2, 4), (2, 5), (3, 4), (3, 5)]
self.assertEqual(gu.cross(e1, e2), target)
def test_comb2(self):
self.assertEqual(gu.comb2([]), [])
self.assertEqual(gu.comb2([1]), [])
self.assertEqual(gu.comb2([1, 2]), [(1, 2)])
self.assertEqual(gu.comb2([1, 2, 3]), [(1, 2), (1, 3), (2, 3)])
def test_comb3(self):
self.assertEqual(gu.comb3([]), [])
self.assertEqual(gu.comb3([1]), [])
self.assertEqual(gu.comb3([1, 2]), [])
self.assertEqual(gu.comb3([1, 2, 3]), [(1, 2, 3)])
self.assertEqual(
gu.comb3([1, 2, 3, 4]), [(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
)
def test_comb4(self):
self.assertEqual(gu.comb4([]), [])
self.assertEqual(gu.comb4([1]), [])
self.assertEqual(gu.comb4([1, 2]), [])
self.assertEqual(gu.comb4([1, 2, 3]), [])
self.assertEqual(gu.comb4([1, 2, 3, 4]), [(1, 2, 3, 4)])
self.assertEqual(
gu.comb4([1, 2, 3, 4, 5]),
[(1, 2, 3, 4), (1, 2, 3, 5), (1, 2, 4, 5), (1, 3, 4, 5), (2, 3, 4, 5)],
)
def test_perm2(self):
self.assertEqual(gu.perm2([]), [])
self.assertEqual(gu.perm2([1]), [])
self.assertEqual(gu.perm2([1, 2]), [(1, 2), (2, 1)])
self.assertEqual(
gu.perm2([1, 2, 3]), [(1, 2), (2, 1), (1, 3), (3, 1), (2, 3), (3, 2)]
)
def test_perm3(self):
self.assertEqual(gu.perm3([]), [])
self.assertEqual(gu.perm3([1]), [])
self.assertEqual(gu.perm3([1, 2]), [])
self.assertEqual(
gu.perm3([1, 2, 3]),
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)],
)
self.assertEqual(
gu.perm3([1, 2, 3, 4]),
[
(1, 2, 3),
(1, 2, 4),
(1, 3, 2),
(1, 3, 4),
(1, 4, 2),
(1, 4, 3),
(2, 1, 3),
(2, 1, 4),
(2, 3, 1),
(2, 3, 4),
(2, 4, 1),
(2, 4, 3),
(3, 1, 2),
(3, 1, 4),
(3, 2, 1),
(3, 2, 4),
(3, 4, 1),
(3, 4, 2),
(4, 1, 2),
(4, 1, 3),
(4, 2, 1),
(4, 2, 3),
(4, 3, 1),
(4, 3, 2),
],
)
def test_perm4(self):
self.assertEqual(gu.perm3([]), [])
self.assertEqual(gu.perm3([1]), [])
self.assertEqual(gu.perm3([1, 2]), [])
self.assertEqual(gu.perm4([1, 2, 3]), [])
self.assertEqual(
gu.perm4([1, 2, 3, 4]),
[
(1, 2, 3, 4),
(1, 2, 4, 3),
(1, 3, 2, 4),
(1, 3, 4, 2),
(1, 4, 2, 3),
(1, 4, 3, 2), # pylint: disable=line-too-long
(2, 1, 3, 4),
(2, 1, 4, 3),
(2, 3, 1, 4),
(2, 3, 4, 1),
(2, 4, 1, 3),
(2, 4, 3, 1), # pylint: disable=line-too-long
(3, 1, 2, 4),
(3, 1, 4, 2),
(3, 2, 1, 4),
(3, 2, 4, 1),
(3, 4, 1, 2),
(3, 4, 2, 1), # pylint: disable=line-too-long
(4, 1, 2, 3),
(4, 1, 3, 2),
(4, 2, 1, 3),
(4, 2, 3, 1),
(4, 3, 1, 2),
(4, 3, 2, 1),
], # pylint: disable=line-too-long
)
if __name__ == '__main__':
absltest.main()