-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_serializer_ulkb_not.py
218 lines (187 loc) · 6.95 KB
/
test_serializer_ulkb_not.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# Copyright (C) 2023 IBM Corp.
# SPDX-License-Identifier: Apache-2.0
from ulkb import *
from .test_serializer_ulkb import TestSerializerULKB
from .tests import main
class TestSerializerULKB_Not(TestSerializerULKB):
def test_defaults(self):
a = TypeVariable('a')
x, y = Variables('x', 'y', a)
f = Constant('f', FunctionType(a, a))
g = Constant('g', FunctionType(a, a, a))
self.assert_to_ulkb(
(Not(Truth()),
'¬(⊤ : 𝔹) : 𝔹'),
(Not(Not(Truth())),
'¬¬(⊤ : 𝔹) : 𝔹'),
(Not(Falsity()),
'¬(⊥ : 𝔹) : 𝔹'),
(Not(Not(Falsity())),
'¬¬(⊥ : 𝔹) : 𝔹'),
(Not(f(x@bool)),
'¬(f : 𝔹 → 𝔹) (x : 𝔹) : 𝔹'),
(Not(Equal(x, x)),
'(x : a) ≠ (x : a) : 𝔹'),
(Not(Equal(Not(x@bool), x@bool)),
'¬(¬(x : 𝔹) ↔ (x : 𝔹)) : 𝔹'))
def test_ensure_ascii(self):
a = TypeVariable('a')
x, y = Variables('x', 'y', a)
f = Constant('f', FunctionType(a, a))
g = Constant('g', FunctionType(a, a, a))
self.assert_to_ulkb(
(Not(f(x@bool)),
'not f x : bool'),
ensure_ascii=True, show_types=False)
def test_show_annotations(self):
a = TypeVariable('a')
x, y = Variables('x', 'y', a)
f = Constant('f', FunctionType(a, a))
g = Constant('g', FunctionType(a, a, a))
self.assert_to_ulkb(
(Not((y@bool)@{'i': 1}, j=2),
'¬y : 𝔹'),
show_annotations=False, show_types=False)
y = y@bool
self.assert_to_ulkb(
(Not(y@{'i': 1}, j=2),
'¬(y {i=1} : 𝔹) {j=2} : 𝔹'),
(Not(Not(y@{'i': 1}, j=2), k=3),
'¬(¬(y {i=1} : 𝔹) {j=2}) {k=3} : 𝔹'),
(Not(Equal(x@{'i': 1}, x)),
'(x {i=1} : a) ≠ (x : a) : 𝔹'),
show_annotations=True)
self.assert_to_ulkb(
(Not(y@{'i': 1}, j=2),
'not (y {i=1} : bool) {j=2} : bool'),
show_annotations=True, ensure_ascii=True)
def test_show_parentheses(self):
a = TypeVariable('a')
x, y = Variables('x', 'y', a)
f = Constant('f', FunctionType(a, a))
g = Constant('g', FunctionType(a, a, a))
self.assert_to_ulkb(
(Not(Equal(x@{'i': 1}, x)),
'¬(x = x) : 𝔹'),
show_parentheses=True, show_types=False)
y = y@bool
self.assert_to_ulkb(
(Not(y@{'i': 1}, j=2),
'¬(y {i=1}) {j=2} : 𝔹'),
(Not(Not(y@{'i': 1}, j=2), k=3),
'¬(¬(y {i=1}) {j=2}) {k=3} : 𝔹'),
(Not(Equal(x@{'i': 1}, x)),
'¬((x {i=1}) = x) : 𝔹'),
show_annotations=True, show_parentheses=True, show_types=False)
self.assert_to_ulkb(
(Not(y@{'i': 1}, j=2),
'not (y {i=1}) {j=2} : bool'),
(Not(Not(y@{'i': 1}, j=2), k=3),
'not (not (y {i=1}) {j=2}) {k=3} : bool'),
show_annotations=True, ensure_ascii=True, show_parentheses=True,
show_types=False)
self.assert_to_ulkb(
(Not(Falsity()),
'¬⊥ : 𝔹'),
(Not(Equal(x@bool, x@bool)),
'¬(x ↔ x) : 𝔹'),
(Equal(Not(y), Not(Not(Equal(y, y)))),
'¬y ↔ ¬¬(y ↔ y) : 𝔹'),
show_types=False, show_parentheses=False)
self.assert_to_ulkb(
(Not(Falsity()),
'¬⊥ : 𝔹'),
(Not(Equal(x@bool, x@bool)),
'¬(x ↔ x) : 𝔹'),
(Equal(Not(y), Not(Not(Equal(y, y)))),
'(¬y) ↔ (¬¬(y ↔ y)) : 𝔹'),
show_types=False, show_parentheses=True)
self.assert_to_ulkb(
(Not(Equal(f(x)@{'i': x}, x)),
'¬((f x {i=⟨x : a⟩}) = x) : 𝔹'),
show_parentheses=True, show_annotations=True, omit_types=True)
def test_show_types(self):
a = TypeVariable('a')
x, y = Variables('x', 'y', a)
f = Constant('f', FunctionType(a, a))
g = Constant('g', FunctionType(a, a, a))
self.assert_to_ulkb(
(Not(x@bool),
'¬(x : 𝔹) : 𝔹'),
(Not(Equal(x, x)),
'(x : a) ≠ (x : a) : 𝔹'),
(g(Not(x@bool), Not(f(x@bool))), '\
(g : 𝔹 → 𝔹 → 𝔹) (¬(x : 𝔹)) (¬(f : 𝔹 → 𝔹) (x : 𝔹)) : 𝔹'),
show_types=True)
self.assert_to_ulkb(
(Not(x@bool),
'¬x : 𝔹'),
(Not(Equal(x, x)),
'x ≠ x : 𝔹'),
(g(Not(x@bool), Not(f(x@bool))), 'g (¬x) (¬f x) : 𝔹'),
show_types=False)
y = y@bool
self.assert_to_ulkb(
(f(Not(f(y))),
'(f : 𝔹 → 𝔹) (¬(f : 𝔹 → 𝔹) (y : 𝔹)) : 𝔹'),
show_types=True)
self.assert_to_ulkb(
(Not(y),
'¬y : 𝔹'),
(f(Not(f(y))),
'f (¬f y) : 𝔹'),
show_types=False)
def test_misc(self):
a = TypeVariable('a')
b = TypeVariable('b')
a = TypeVariable('a')
f = Constant('f', a >> a)
g = Constant('g', (a, a) >> a)
x, y, z, w = Variables('x', 'y', 'z', 'w', a)
A = Variable('A', bool)
t = Not(Not(Not(A)), k1=1, k2=2)
self.assert_to_ulkb(
(t,
'¬¬¬(A : 𝔹) : 𝔹'),
(Not(Or(true, false)),
'¬((⊤ : 𝔹) ∨ (⊥ : 𝔹)) : 𝔹'))
self.assert_to_ulkb(
(t,
'¬¬¬(A : 𝔹) {k1=1, k2=2} : 𝔹'),
show_annotations=True,)
self.assert_to_ulkb(
(t,
'not not not (A : bool) {k1=1, k2=2} : bool'),
ensure_ascii=True, show_annotations=True)
self.assert_to_ulkb(
(t,
'¬¬¬A {k1=1, k2=2} : 𝔹'),
omit_types=True, show_annotations=True)
self.assert_to_ulkb(
(t,
'¬¬¬(A : 𝔹) {k1=1, k2=2} : 𝔹'),
show_annotations=True)
self.assert_to_ulkb(
(t,
'¬¬¬A : 𝔹'),
omit_types=True, omit_annotations=True)
P, Q, R, = Constants('P', 'Q', 'R', bool)
x, y, z = Variables('x', 'y', 'z', bool)
self.assert_to_ulkb(
(Not(P),
'¬(P : 𝔹) : 𝔹'))
self.assert_to_ulkb(
(Not(P),
'¬(P : 𝔹) : 𝔹'),
omit_parentheses=False)
self.assert_to_ulkb(
(Not(g(x, g(y, z))), '\
not (g : bool -> bool -> bool) (x : bool) \
((g : bool -> bool -> bool) (y : bool) (z : bool)) : bool'),
ensure_ascii=True)
self.assert_to_ulkb(
(Not(g(x, g(y, z))),
'¬g x (g y z) : 𝔹'),
show_types=False)
if __name__ == '__main__':
main()