-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_syntaxes_invalid.py
147 lines (123 loc) · 4.52 KB
/
test_syntaxes_invalid.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
146
147
from unittest import TestCase
from search_space.errors import UnSupportOpError
from search_space.spaces.search_space import BasicSearchSpace
from search_space.spaces.asts import constraints
from test_syntaxes_valid import cmp_ast
from search_space.dsl import Domain
from search_space.errors import InvalidSampler
class ConstraintInvalidBasicSyntaxes(TestCase):
def setUp(self) -> None:
self.space = BasicSearchSpace((), None)
def test_basic_rmod(self):
try:
ast = self.space.__build_constraint__(lambda x: 10 % x)
sample_ast = constraints.SegmentationModOp(
constraints.NaturalValue(10),
constraints.SelfNode
)
cmp_ast(sample_ast, ast)
assert False
except TypeError:
pass
def test_invalid_or(self):
try:
ast = self.space.__build_constraint__(lambda x: False | x < 3)
assert False, 'lambda x: False | x < 3'
except UnSupportOpError:
pass
try:
ast = self.space.__build_constraint__(lambda x: x > 5 | x < 3)
assert False, 'lambda x: x > 5 | x < 3'
except UnSupportOpError:
pass
def test_invalid_and(self):
try:
ast = self.space.__build_constraint__(lambda x: True & x < 3)
assert False, 'lambda x: True & x < 3'
except UnSupportOpError:
pass
try:
ast = self.space.__build_constraint__(lambda x: x > 5 & x < 3)
assert False, 'lambda x: x > 5 & x < 3'
except UnSupportOpError:
pass
def test_invalid_eq(self):
try:
ast = self.space.__build_constraint__(lambda x: (x == x) < 3)
assert False, 'lambda x: (x == x) < 3'
except UnSupportOpError:
pass
try:
ast = self.space.__build_constraint__(lambda x: (x == x) + 3)
assert False, 'lambda x: x == x + 3'
except UnSupportOpError:
pass
def test_invalid_neq(self):
try:
ast = self.space.__build_constraint__(lambda x: (x != x) > 3)
assert False, 'lambda x: (x != x) > 3'
except UnSupportOpError:
pass
try:
ast = self.space.__build_constraint__(lambda x: (x != x) - 3)
assert False, 'lambda x: x != x - 3'
except UnSupportOpError:
pass
def test_invalid_less(self):
try:
ast = self.space.__build_constraint__(lambda x: (x < x) == 3)
assert False, 'lambda x: (x < x) == 3'
except UnSupportOpError:
pass
try:
ast = self.space.__build_constraint__(lambda x: (x < x) * 3)
assert False, 'lambda x: x < x * 3'
except UnSupportOpError:
pass
def test_invalid_great(self):
try:
ast = self.space.__build_constraint__(lambda x: (x > x) <= 3)
assert False, 'lambda x: (x > x) <= 3'
except UnSupportOpError:
pass
try:
ast = self.space.__build_constraint__(lambda x: (x > x) % 3)
assert False, 'lambda x: x > x % 3'
except UnSupportOpError:
pass
def test_invalid_sum(self):
try:
ast = self.space.__build_constraint__(lambda x: (x + 3)[3])
assert False, 'lambda x: (x + 3)[3]'
except UnSupportOpError:
pass
try:
ast = self.space.__build_constraint__(lambda x: (x + 3).member)
assert False, 'lambda x: (x + 3).member'
except UnSupportOpError:
pass
def test_invalid_mod(self):
try:
ast = self.space.__build_constraint__(lambda x: (x % 3 == 1) + 5)
assert False, 'lambda x: (x % 3 == 1) + 5'
except UnSupportOpError:
pass
try:
ast = self.space.__build_constraint__(lambda x: (x % 3 == 1) < 5)
assert False, 'lambda x: x % 3 == 1 < 5'
except UnSupportOpError:
pass
def test_list_space(self):
try:
matrix_space = Domain[int][6][6][6]() | (
lambda x, i, j: x[i][j] == x[j][i])
matrix, _ = matrix_space.get_sample()
assert False
except InvalidSampler:
pass
# def test():
# matrix, _ = matrix_space.get_sample()
# for i, row in enumerate(matrix):
# for j, item in enumerate(row):
# assert item == matrix[j][i]
# replay_function(test)