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
|
#####################
## test_grammar.py
## Top contributors (to current version):
## Yoni Zohar, Makai Mann, Mudathir Mohamed
## This file is part of the CVC4 project.
## Copyright (c) 2009-2020 by the authors listed in the file AUTHORS
## in the top-level source directory and their institutional affiliations.
## All rights reserved. See the file COPYING in the top-level source
## directory for licensing information.
##
## Translated from test/unit/api/grammar_black.h
##
import pytest
import pycvc4
from pycvc4 import kinds
def test_add_rule():
solver = pycvc4.Solver()
boolean = solver.getBooleanSort()
integer = solver.getIntegerSort()
nullTerm = pycvc4.Term(solver)
start = solver.mkVar(boolean)
nts = solver.mkVar(boolean)
# expecting no error
g = solver.mkSygusGrammar([], [start])
g.addRule(start, solver.mkBoolean(False))
# expecting errors
with pytest.raises(Exception):
g.addRule(nullTerm, solver.mkBoolean(false))
with pytest.raises(Exception):
g.addRule(start, nullTerm)
with pytest.raises(Exception):
g.addRule(nts, solver.mkBoolean(false))
with pytest.raises(Exception):
g.addRule(start, solver.mkInteger(0))
# expecting no errors
solver.synthFun("f", {}, boolean, g)
# expecting an error
with pytest.raises(Exception):
g.addRule(start, solver.mkBoolean(false))
def test_add_rules():
solver = pycvc4.Solver()
boolean = solver.getBooleanSort()
integer = solver.getIntegerSort()
nullTerm = pycvc4.Term(solver)
start = solver.mkVar(boolean)
nts = solver.mkVar(boolean)
g = solver.mkSygusGrammar([], [start])
g.addRules(start, {solver.mkBoolean(False)})
#Expecting errors
with pytest.raises(Exception):
g.addRules(nullTerm, solver.mkBoolean(False))
with pytest.raises(Exception):
g.addRules(start, {nullTerm})
with pytest.raises(Exception):
g.addRules(nts, {solver.mkBoolean(False)})
with pytest.raises(Exception):
g.addRules(start, {solver.mkInteger(0)})
#Expecting no errors
solver.synthFun("f", {}, boolean, g)
#Expecting an error
with pytest.raises(Exception):
g.addRules(start, solver.mkBoolean(False))
def testAddAnyConstant():
solver = pycvc4.Solver()
boolean = solver.getBooleanSort()
nullTerm = pycvc4.Term(solver)
start = solver.mkVar(boolean)
nts = solver.mkVar(boolean)
g = solver.mkSygusGrammar({}, {start})
g.addAnyConstant(start)
g.addAnyConstant(start)
with pytest.raises(Exception):
g.addAnyConstant(nullTerm)
with pytest.raises(Exception):
g.addAnyConstant(nts)
solver.synthFun("f", {}, boolean, g)
with pytest.raises(Exception):
g.addAnyConstant(start)
def testAddAnyVariable():
solver = pycvc4.Solver()
boolean = solver.getBooleanSort()
nullTerm = pycvc4.Term(solver)
x = solver.mkVar(boolean)
start = solver.mkVar(boolean)
nts = solver.mkVar(boolean)
g1 = solver.mkSygusGrammar({x}, {start})
g2 = solver.mkSygusGrammar({}, {start})
g1.addAnyVariable(start)
g1.addAnyVariable(start)
g2.addAnyVariable(start)
with pytest.raises(Exception):
g1.addAnyVariable(nullTerm)
with pytest.raises(Exception):
g1.addAnyVariable(nts)
solver.synthFun("f", {}, boolean, g1)
with pytest.raises(Exception):
g1.addAnyVariable(start)
|