-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest_expr.py
82 lines (55 loc) · 1.85 KB
/
test_expr.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
import hypothesis.strategies as st
from hypothesis import given
from aiger.expr import atom, ite
@given(st.data())
def test_expr_and(data):
x, y = atom('x'), atom('y')
expr = x & y
vals = {f'{i}': data.draw(st.booleans()) for i in expr.inputs}
assert (x(vals) and y(vals)) == expr(vals)
@given(st.data())
def test_expr_and2(data):
x = atom('x')
expr = x & x
vals = {f'{i}': data.draw(st.booleans()) for i in expr.inputs}
assert x(vals) == expr(vals)
@given(st.data())
def test_expr_or(data):
x, y = atom('x'), atom('y')
expr = x | y
vals = {f'{i}': data.draw(st.booleans()) for i in expr.inputs}
assert (x(vals) or y(vals)) == expr(vals)
@given(st.data())
def test_expr_xor(data):
x, y = atom('x'), atom('y')
expr = x ^ y
vals = {f'{i}': data.draw(st.booleans()) for i in expr.inputs}
assert (x(vals) ^ y(vals)) == expr(vals)
@given(st.data())
def test_expr_eq(data):
x, y = atom('x'), atom('y')
expr = x == y
vals = {f'{i}': data.draw(st.booleans()) for i in expr.inputs}
assert (x(vals) == y(vals)) == expr(vals)
@given(st.data())
def test_expr_implies(data):
x, y = atom('x'), atom('y')
expr = x.implies(y)
vals = {f'{i}': data.draw(st.booleans()) for i in expr.inputs}
assert ((not x(vals)) or y(vals)) == expr(vals)
@given(st.data())
def test_expr_invert(data):
x = atom('x')
expr = ~x
vals = {f'{i}': data.draw(st.booleans()) for i in expr.inputs}
assert x(vals) == (not expr(vals))
@given(st.data())
def test_expr_ite(data):
x, y, z = map(atom, 'xyz')
expr = ite(x, y, z)
vals = {f'{i}': data.draw(st.booleans()) for i in expr.inputs}
assert expr(vals) == (vals['y'] if vals['x'] else vals['z'])
def test_with_output():
x, y, z = map(atom, 'xyz')
expr = ite(x, y, z).with_output('xyz')
assert expr.with_output('xyz')