This PR adds tests for almost everything that is not yet covered by the python API tests.
std::string DatatypeConstructorDecl::toString() const
{
CVC5_API_TRY_CATCH_BEGIN;
+ CVC5_API_CHECK_NOT_NULL;
//////// all checks before this line
std::stringstream ss;
ss << *d_ctor;
void addAnyConstant(Term ntSymbol) except +
void addAnyVariable(Term ntSymbol) except +
void addRules(Term ntSymbol, vector[Term] rules) except +
+ string toString() except +
cdef cppclass Sort:
Sort() except +
Datatype getDatatype() except +
Sort instantiate(const vector[Sort]& params) except +
vector[Sort] getInstantiatedParameters() except +
+ Sort substitute(const Sort & es, const Sort & reps) except +
Sort substitute(const vector[Sort] & es, const vector[Sort] & reps) except +
size_t getDatatypeConstructorArity() except +
vector[Sort] getDatatypeConstructorDomainSorts() except +
uint64_t getId() except +
Kind getKind() except +
Sort getSort() except +
+ Term substitute(const Term & es, const Term & reps) except +
Term substitute(const vector[Term] & es, const vector[Term] & reps) except +
bint hasOp() except +
Op getOp() except +
self.solver = solver
self.cgrammar = c_Grammar()
+ def __str__(self):
+ return self.cgrammar.toString().decode()
+
def addRule(self, Term ntSymbol, Term rule):
"""
Add ``rule`` to the set of rules corresponding to ``ntSymbol``.
cdef vector[c_Sort] ces
cdef vector[c_Sort] creplacements
- # normalize the input parameters to be lists
if isinstance(sort_or_list_1, list):
+ # call the API substitute method with lists
assert isinstance(sort_or_list_2, list)
es = sort_or_list_1
replacements = sort_or_list_2
for e, r in zip(es, replacements):
ces.push_back((<Sort?> e).csort)
creplacements.push_back((<Sort?> r).csort)
-
+ sort.csort = self.csort.substitute(ces, creplacements)
else:
- # add the single elements to the vectors
- ces.push_back((<Sort?> sort_or_list_1).csort)
- creplacements.push_back((<Sort?> sort_or_list_2).csort)
+ # call the API substitute method with single sorts
+ sort.csort = self.csort.substitute((<Sort?> sort_or_list_1).csort, (<Sort?> sort_or_list_2).csort)
- # call the API substitute method with lists
- sort.csort = self.csort.substitute(ces, creplacements)
return sort
cdef vector[c_Term] ces
cdef vector[c_Term] creplacements
- # normalize the input parameters to be lists
if isinstance(term_or_list_1, list):
+ # call the API substitute method with lists
assert isinstance(term_or_list_2, list)
es = term_or_list_1
replacements = term_or_list_2
for e, r in zip(es, replacements):
ces.push_back((<Term?> e).cterm)
creplacements.push_back((<Term?> r).cterm)
-
+ term.cterm = self.cterm.substitute(ces, creplacements)
else:
- # add the single elements to the vectors
- ces.push_back((<Term?> term_or_list_1).cterm)
- creplacements.push_back((<Term?> term_or_list_2).cterm)
+ # call the API substitute method with single terms
+ term.cterm = self.cterm.substitute((<Term?> term_or_list_1).cterm, (<Term?> term_or_list_2).cterm)
- # call the API substitute method with lists
- term.cterm = self.cterm.substitute(ces, creplacements)
return term
def hasOp(self):
assert sel.isNull()
# changing the objects to be non-null
- dtypeSpec = solver.mkDatatypeDecl("list");
- cons = solver.mkDatatypeConstructorDecl("cons");
- cons.addSelector("head", solver.getIntegerSort());
- dtypeSpec.addConstructor(cons);
+ dtypeSpec = solver.mkDatatypeDecl("list")
+ cons = solver.mkDatatypeConstructorDecl("cons")
+ cons.addSelector("head", solver.getIntegerSort())
+ dtypeSpec.addConstructor(cons)
+ assert dtypeSpec.getNumConstructors() == 1
+ assert not dtypeSpec.isParametric()
listSort = solver.mkDatatypeSort(dtypeSpec)
- d = listSort.getDatatype();
- consConstr = d[0];
- sel = consConstr[0];
+ d = listSort.getDatatype()
+ consConstr = d[0]
+ sel = consConstr[0]
# verifying that the new objects are non-null
assert not dtypeSpec.isNull()
return cvc5.Solver()
+def test_to_string(solver):
+ solver.setOption("sygus", "true")
+ boolean = solver.getBooleanSort()
+ start = solver.mkVar(boolean)
+ nts = solver.mkVar(boolean)
+ g = solver.mkGrammar([nts], [start])
+ g.addRule(start, solver.mkBoolean(False))
+ str(g)
+
+
def test_add_rule(solver):
solver.setOption("sygus", "true")
boolean = solver.getBooleanSort()
{
std::stringstream ss;
ss << cvc5::modes::LearnedLitType::PREPROCESS;
+ ss << cvc5::UnknownExplanation::UNKNOWN_REASON;
ss << cvc5::Result();
ss << cvc5::Op();
ss << cvc5::SynthResult();
+ ss << cvc5::Grammar();
Sort intsort = d_solver.getIntegerSort();
Term x = d_solver.mkConst(intsort, "x");
ss << std::unordered_set<Term>{x, x};
}
+TEST_F(TestApiBlackUncovered, datatypeApi)
+{
+ DatatypeDecl dtypeSpec = d_solver.mkDatatypeDecl("list");
+ DatatypeConstructorDecl cons = d_solver.mkDatatypeConstructorDecl("cons");
+ cons.addSelector("head", d_solver.getIntegerSort());
+ dtypeSpec.addConstructor(cons);
+ DatatypeConstructorDecl nil = d_solver.mkDatatypeConstructorDecl("nil");
+ dtypeSpec.addConstructor(nil);
+ Sort listSort = d_solver.mkDatatypeSort(dtypeSpec);
+ Datatype d = listSort.getDatatype();
+
+ std::stringstream ss;
+ ss << cons;
+ ss << d.getConstructor("cons");
+ ss << d.getSelector("head");
+ ss << std::vector<DatatypeConstructorDecl>{cons, nil};
+ ss << d;
+
+ {
+ DatatypeConstructor c = d.getConstructor("cons");
+ DatatypeConstructor::const_iterator it;
+ it = c.begin();
+ ASSERT_NE(it, c.end());
+ ASSERT_EQ(it, c.begin());
+ *it;
+ ASSERT_NO_THROW(it->getName());
+ ++it;
+ it++;
+ }
+ {
+ Datatype::const_iterator it;
+ it = d.begin();
+ ASSERT_NE(it, d.end());
+ ASSERT_EQ(it, d.begin());
+ it->getName();
+ *it;
+ ++it;
+ it++;
+ }
+}
+
+TEST_F(TestApiBlackUncovered, termNativeTypes)
+{
+ Term t = d_solver.mkInteger(0);
+ d_solver.mkReal(0);
+ d_solver.mkReal(0, 1);
+ t.isInt32Value();
+ t.getInt32Value();
+ t.isInt64Value();
+ t.getInt64Value();
+ t.isUInt32Value();
+ t.getUInt32Value();
+ t.isUInt64Value();
+ t.getUInt64Value();
+ t.isReal32Value();
+ t.getReal32Value();
+ t.isReal64Value();
+ t.getReal64Value();
+}
+
+TEST_F(TestApiBlackUncovered, termIterators)
+{
+ Term t = d_solver.mkInteger(0);
+ auto it = t.begin();
+ auto it2(it);
+ it++;
+}
+
+TEST_F(TestApiBlackUncovered, checkSatAssumingSingle)
+{
+ Sort boolsort = d_solver.getBooleanSort();
+ Term b = d_solver.mkConst(boolsort, "b");
+ d_solver.checkSatAssuming(b);
+}
+
+TEST_F(TestApiBlackUncovered, mkOpInitializerList)
+{
+ d_solver.mkOp(Kind::BITVECTOR_EXTRACT, {1, 1});
+}
+
+TEST_F(TestApiBlackUncovered, mkTermKind)
+{
+ Term b = d_solver.mkConst(d_solver.getRealSort(), "b");
+ d_solver.mkTerm(Kind::GT, {b, b});
+}
+
TEST_F(TestApiBlackUncovered, getValue)
{
d_solver.setOption("produce-models", "true");