This PR adds a bunch of unit tests for some not yet covered corners of the API.
case TUPLE_PROJECT:
size = d_node->getConst<internal::TupleProjectOp>().getIndices().size();
break;
+ case TABLE_PROJECT:
+ size = d_node->getConst<internal::TableProjectOp>().getIndices().size();
+ break;
default: CVC5_API_CHECK(false) << "Unhandled kind " << kindToString(k);
}
return size;
bool Datatype::isNullHelper() const { return d_dtype == nullptr; }
+std::ostream& operator<<(std::ostream& out, const Datatype& dtype)
+{
+ return out << dtype.toString();
+}
+
/* -------------------------------------------------------------------------- */
/* Grammar */
/* -------------------------------------------------------------------------- */
diffi[termk] = termv
return diffi
- def getValue(self, Term t):
+ def getValue(self, term_or_list):
"""
- Get the value of the given term in the current model.
+ Get the value of the given term or list of terms in the current
+ model.
SMT-LIB:
.. code-block:: smtlib
- ( get-value ( <term> ) )
+ ( get-value ( <term>* ) )
- :param term: The term for which the value is queried.
- :return: The value of the given term.
+ :param term_or_list: The term or list of terms for which the value
+ is queried.
+ :return: The value or list of values of the given term or list of
+ terms.
"""
+ if isinstance(term_or_list, list):
+ return [self.getValue(t) for t in term_or_list]
cdef Term term = Term(self)
- term.cterm = self.csolver.getValue(t.cterm)
+ term.cterm = self.csolver.getValue((<Term> term_or_list).cterm)
return term
def getModelDomainElements(self, Sort s):
cons = d_solver.mkDatatypeConstructorDecl("cons");
cons.addSelector("head", d_solver.getIntegerSort());
dtypeSpec.addConstructor(cons);
+ ASSERT_EQ(dtypeSpec.getNumConstructors(), 1);
+ ASSERT_FALSE(dtypeSpec.isParametric());
Sort listSort = d_solver.mkDatatypeSort(dtypeSpec);
d = listSort.getDatatype();
consConstr = d[0];
ASSERT_FALSE(d.isNull());
ASSERT_FALSE(consConstr.isNull());
ASSERT_FALSE(sel.isNull());
+
+ {
+ std::stringstream ss;
+ ss << cons;
+ ASSERT_EQ(ss.str(), cons.toString());
+ }
+ {
+ std::stringstream ss;
+ ss << sel;
+ ASSERT_EQ(ss.str(), sel.toString());
+ }
+ {
+ std::stringstream ss;
+ ss << consConstr;
+ ASSERT_EQ(ss.str(), consConstr.toString());
+ }
+ {
+ std::stringstream ss;
+ ss << d;
+ ASSERT_EQ(ss.str(), d.toString());
+ }
+
+ {
+ Datatype::const_iterator it;
+ it = d.begin();
+ ASSERT_TRUE(it != d.end());
+ ASSERT_FALSE(it->isNull());
+ ASSERT_FALSE((*it).isNull());
+ auto tmp = it;
+ tmp++;
+ ASSERT_EQ(tmp, d.end());
+ tmp = it;
+ ++tmp;
+ ASSERT_EQ(tmp, d.end());
+ }
+
+ {
+ DatatypeConstructor::const_iterator it;
+ it = consConstr.begin();
+ ASSERT_TRUE(it != consConstr.end());
+ ASSERT_FALSE(it->isNull());
+ ASSERT_FALSE((*it).isNull());
+ auto tmp = it;
+ tmp++;
+ ASSERT_EQ(tmp, consConstr.end());
+ tmp = it;
+ ++tmp;
+ ASSERT_EQ(tmp, consConstr.end());
+ }
}
TEST_F(TestApiBlackDatatype, mkDatatypeSorts)
{
};
+TEST_F(TestApiBlackGrammar, toString)
+{
+ d_solver.setOption("sygus", "true");
+ Sort boolean = d_solver.getBooleanSort();
+ Term start = d_solver.mkVar(boolean);
+ Grammar g;
+ g = d_solver.mkGrammar({}, {start});
+ g.addRule(start, d_solver.mkBoolean(false));
+
+ {
+ std::stringstream ss;
+ ss << g;
+ ASSERT_EQ(ss.str(), g.toString());
+ }
+}
+
TEST_F(TestApiBlackGrammar, addRule)
{
d_solver.setOption("sygus", "true");
std::vector<uint32_t> indices = {0, 3, 2, 0, 1, 2};
Op tupleProject = d_solver.mkOp(TUPLE_PROJECT, indices);
ASSERT_EQ(indices.size(), tupleProject.getNumIndices());
+
+ Op tableProject = d_solver.mkOp(TABLE_PROJECT, indices);
+ ASSERT_EQ(indices.size(), tableProject.getNumIndices());
}
TEST_F(TestApiBlackOp, subscriptOperator)
Op iand = d_solver.mkOp(IAND, {11});
Op fpToUbv = d_solver.mkOp(FLOATINGPOINT_TO_UBV, {12});
Op fpToSbv = d_solver.mkOp(FLOATINGPOINT_TO_SBV, {13});
+ Op regexpRepeat = d_solver.mkOp(REGEXP_REPEAT, {14});
ASSERT_EQ(4, divisible[0].getUInt32Value());
ASSERT_EQ(5, bvRepeat[0].getUInt32Value());
ASSERT_EQ(11, iand[0].getUInt32Value());
ASSERT_EQ(12, fpToUbv[0].getUInt32Value());
ASSERT_EQ(13, fpToSbv[0].getUInt32Value());
+ ASSERT_EQ(14, regexpRepeat[0].getUInt32Value());
// Operators with 2 indices
Op bvExtract = d_solver.mkOp(BITVECTOR_EXTRACT, {1, 0});
Term x = d_solver.mkConst(d_solver.getBooleanSort(), "x");
d_solver.assertFormula(x.eqTerm(x).notTerm());
ASSERT_THROW(d_solver.getValue(x), CVC5ApiRecoverableException);
+
+ try {
+ d_solver.getValue(x);
+ }
+ catch (const CVC5ApiRecoverableException& e)
+ {
+ ASSERT_NO_THROW(e.what());
+ ASSERT_NO_THROW(e.getMessage());
+ }
}
TEST_F(TestApiBlackSolver, supportsFloatingPoint)
"\"asdf\\u{5c}nasdf\"");
ASSERT_EQ(d_solver.mkString("asdf\\u{005c}nasdf", true).toString(),
"\"asdf\\u{5c}nasdf\"");
+ std::wstring s;
+ ASSERT_EQ(d_solver.mkString(s).getStringValue(), s);
}
TEST_F(TestApiBlackSolver, mkTerm)
}
}
+TEST_F(TestApiBlackSolver, getAssertions)
+{
+ Term a = d_solver.mkConst(d_solver.getBooleanSort(), "a");
+ Term b = d_solver.mkConst(d_solver.getBooleanSort(), "b");
+ d_solver.assertFormula(a);
+ d_solver.assertFormula(b);
+ std::vector<Term> asserts{a, b};
+ ASSERT_EQ(d_solver.getAssertions(), asserts);
+}
+
TEST_F(TestApiBlackSolver, getInfo)
{
ASSERT_NO_THROW(d_solver.getInfo("name"));
ASSERT_EQ(dopts.in().rdbuf(), std::cin.rdbuf());
ASSERT_EQ(dopts.out().rdbuf(), std::cout.rdbuf());
}
-
+
TEST_F(TestApiBlackSolver, getStatistics)
{
ASSERT_NO_THROW(cvc5::Stat());
ASSERT_NO_THROW(d_solver.getValue(sum));
ASSERT_NO_THROW(d_solver.getValue(p_f_y));
+ std::vector<Term> a;
+ ASSERT_NO_THROW(a.emplace_back(d_solver.getValue(x)));
+ ASSERT_NO_THROW(a.emplace_back(d_solver.getValue(y)));
+ ASSERT_NO_THROW(a.emplace_back(d_solver.getValue(z)));
+ std::vector<Term> b;
+ ASSERT_NO_THROW(b = d_solver.getValue({x,y,z}));
+ ASSERT_EQ(a,b);
+
Solver slv;
ASSERT_THROW(slv.getValue(x), CVC5ApiException);
}
ASSERT_EQ(listhead.getOp(), Op(&d_solver, APPLY_SELECTOR));
}
+TEST_F(TestApiWhiteSolver, printStatisticsSafe)
+{
+ testing::internal::CaptureStdout();
+ d_solver.printStatisticsSafe(STDOUT_FILENO);
+ testing::internal::GetCapturedStdout();
+}
+
} // namespace test
} // namespace cvc5::internal
ASSERT_FALSE(res.hasNoSolution());
ASSERT_FALSE(res.isUnknown());
ASSERT_EQ(res.toString(), "(SOLUTION)");
+ {
+ std::stringstream ss;
+ ss << res;
+ ASSERT_EQ(res.toString(), ss.str());
+ }
}
TEST_F(TestApiBlackSynthResult, hasNoSolution)
Term tnull;
ASSERT_THROW(tnull.getNumChildren(), CVC5ApiException);
+ Term::const_iterator it;
+ it = t1.begin();
+ ASSERT_TRUE((*it).isIntegerValue());
+ it++;
+ ASSERT_TRUE((*it).isIntegerValue());
+ ++it;
+ ASSERT_EQ(it, t1.end());
+
// apply term f(2)
Sort intSort = d_solver.getIntegerSort();
Sort fsort = d_solver.mkFunctionSort({intSort}, intSort);
ASSERT_EQ(x.toString(), "x");
}
-TEST_F(TestApiBlackTerm, toString) { ASSERT_NO_THROW(Term().toString()); }
+TEST_F(TestApiBlackTerm, toString) {
+ ASSERT_NO_THROW(Term().toString());
+
+ Sort intsort = d_solver.getIntegerSort();
+ Term x = d_solver.mkConst(intsort, "x");
+ std::stringstream ss;
+
+ ss << std::vector<Term>{x, x};
+ ss << std::set<Term>{x, x};
+ ss << std::unordered_set<Term>{x, x};
+}
} // namespace test
} // namespace cvc5::internal
Op iand = d_solver.mkOp(IAND, 11);
Op fpToUbv = d_solver.mkOp(FLOATINGPOINT_TO_UBV, 12);
Op fpToSbv = d_solver.mkOp(FLOATINGPOINT_TO_SBV, 13);
+ Op regexpRepeat = d_solver.mkOp(REGEXP_REPEAT, 14);
assertEquals(4, divisible.get(0).getIntegerValue().intValue());
assertEquals(5, bvRepeat.get(0).getIntegerValue().intValue());
assertEquals(11, iand.get(0).getIntegerValue().intValue());
assertEquals(12, fpToUbv.get(0).getIntegerValue().intValue());
assertEquals(13, fpToSbv.get(0).getIntegerValue().intValue());
+ assertEquals(14, regexpRepeat.get(0).getIntegerValue().intValue());
// Operators with 2 indices
Op bvExtract = d_solver.mkOp(BITVECTOR_EXTRACT, 1, 0);
{
};
+TEST_F(TestApiBlackUncovered, exception_getmessage)
+{
+ d_solver.setOption("produce-models", "true");
+ Term x = d_solver.mkConst(d_solver.getBooleanSort(), "x");
+ d_solver.assertFormula(x.eqTerm(x).notTerm());
+
+ ASSERT_THROW(d_solver.getValue(x), CVC5ApiRecoverableException);
+
+ try {
+ d_solver.getValue(x);
+ }
+ catch (const CVC5ApiRecoverableException& e)
+ {
+ ASSERT_NO_THROW(e.getMessage());
+ }
+}
+
TEST_F(TestApiBlackUncovered, streaming_operators)
{
- std::stringstream ss;
- ss << cvc5::modes::LearnedLitType::PREPROCESS;
- ss << cvc5::SynthResult();
+ std::stringstream ss;
+ ss << cvc5::modes::LearnedLitType::PREPROCESS;
+ ss << cvc5::Result();
+ ss << cvc5::Op();
+ ss << cvc5::SynthResult();
+
+ Sort intsort = d_solver.getIntegerSort();
+ Term x = d_solver.mkConst(intsort, "x");
+
+ ss << std::vector<Term>{x, x};
+ ss << std::set<Term>{x, x};
+ ss << std::unordered_set<Term>{x, x};
+}
+
+TEST_F(TestApiBlackUncovered, hash)
+{
+ std::hash<Op>()(Op());
+ std::hash<Sort>()(Sort());
+}
+
+TEST_F(TestApiBlackUncovered, isOutputOn)
+{
+ d_solver.isOutputOn("inst");
+ d_solver.getOutput("inst");
}
TEST_F(TestApiBlackUncovered, Options)
tuple_project_op = solver.mkOp(Kind.TUPLE_PROJECT, *indices)
assert len(indices) == tuple_project_op.getNumIndices()
+ table_project_op = solver.mkOp(Kind.TABLE_PROJECT, *indices)
+ assert len(indices) == table_project_op.getNumIndices()
+
def test_subscript_operator(solver):
# Operators with 0 indices
iand = solver.mkOp(Kind.IAND, 11)
floatingpoint_to_ubv = solver.mkOp(Kind.FLOATINGPOINT_TO_UBV, 12)
floatingopint_to_sbv = solver.mkOp(Kind.FLOATINGPOINT_TO_SBV, 13)
+ regexp_repeat = solver.mkOp(Kind.REGEXP_REPEAT, 14)
assert 4 == divisible[0].getIntegerValue()
assert 5 == bitvector_repeat[0].getIntegerValue()
assert 11 == iand[0].getIntegerValue()
assert 12 == floatingpoint_to_ubv[0].getIntegerValue()
assert 13 == floatingopint_to_sbv[0].getIntegerValue()
+ assert 14 == regexp_repeat[0].getIntegerValue()
# Operators with 2 indices
bitvector_extract = solver.mkOp(Kind.BITVECTOR_EXTRACT, 1, 0)
str(solver.mkString("asdf\\nasdf")) == "\"asdf\\u{5c}nasdf\""
str(solver.mkString("asdf\\u{005c}nasdf", True)) ==\
"\"asdf\\u{5c}nasdf\""
+ s = ""
+ assert solver.mkString(s).getStringValue() == s
def test_mk_term(solver):
idx = idx + 1
+def test_get_assertions(solver):
+ a = solver.mkConst(solver.getBooleanSort(), 'a')
+ b = solver.mkConst(solver.getBooleanSort(), 'b')
+ solver.assertFormula(a)
+ solver.assertFormula(b)
+ asserts = [a,b]
+ assert solver.getAssertions() == asserts
+
+
def test_get_info(solver):
solver.getInfo("name")
with pytest.raises(RuntimeError):
solver.getValue(summ)
solver.getValue(p_f_y)
+ a = [solver.getValue(x), solver.getValue(y), solver.getValue(z)]
+ b = solver.getValue([x,y,z])
+ assert a == b
+
slv = cvc5.Solver()
with pytest.raises(RuntimeError):
slv.getValue(x)
nullt.isCardinalityConstraint()
-
def test_term_scoped_to_string(solver):
intsort = solver.getIntegerSort()
x = solver.mkConst(intsort, "x")
{
};
+TEST_F(TestApiBlackUncovered, exception_getmessage)
+{
+ d_solver.setOption("produce-models", "true");
+ Term x = d_solver.mkConst(d_solver.getBooleanSort(), "x");
+ d_solver.assertFormula(x.eqTerm(x).notTerm());
+
+ ASSERT_THROW(d_solver.getValue(x), CVC5ApiRecoverableException);
+
+ try {
+ d_solver.getValue(x);
+ }
+ catch (const CVC5ApiRecoverableException& e)
+ {
+ ASSERT_NO_THROW(e.getMessage());
+ }
+}
+
TEST_F(TestApiBlackUncovered, streaming_operators)
{
- std::stringstream ss;
- ss << cvc5::modes::LearnedLitType::PREPROCESS;
- ss << cvc5::SynthResult();
+ std::stringstream ss;
+ ss << cvc5::modes::LearnedLitType::PREPROCESS;
+ ss << cvc5::Result();
+ ss << cvc5::Op();
+ ss << cvc5::SynthResult();
+
+ Sort intsort = d_solver.getIntegerSort();
+ Term x = d_solver.mkConst(intsort, "x");
+
+ ss << std::vector<Term>{x, x};
+ ss << std::set<Term>{x, x};
+ ss << std::unordered_set<Term>{x, x};
+}
+
+TEST_F(TestApiBlackUncovered, getValue)
+{
+ d_solver.setOption("produce-models", "true");
+ Sort boolsort = d_solver.getBooleanSort();
+ Term b = d_solver.mkConst(boolsort, "b");
+ d_solver.assertFormula(b);
+ d_solver.checkSat();
+ d_solver.getValue({b, b, b});
+}
+
+TEST_F(TestApiBlackUncovered, isOutputOn)
+{
+ d_solver.isOutputOn("inst");
+ d_solver.getOutput("inst");
}
TEST_F(TestApiBlackUncovered, Options)