This PR complements #8422 by adding a tester and a getter for cardinality constraints to the python API. The corresponding test from solver_black is translated and included.
Term operator*() except +
const_iterator begin() except +
const_iterator end() except +
+ bint isCardinalityConstraint() except +
+ pair[Sort, uint32_t] getCardinalityConstraint() except +
bint isConstArray() except +
bint isBooleanValue() except +
elems.append(term)
return elems
+ def isCardinalityConstraint(self):
+ """
+ .. warning:: This method is experimental and may change in future
+ versions.
+ :return: True if the term is a cardinality constraint.
+ """
+ return self.cterm.isCardinalityConstraint()
+
+ def getCardinalityConstraint(self):
+ """
+ .. warning:: This method is experimental and may change in future
+ versions.
+ :return: the sort the cardinality constraint is for and its upper bound.
+ """
+ cdef pair[c_Sort, uint32_t] p
+ p = self.cterm.getCardinalityConstraint()
+ cdef Sort sort = Sort(self.solver)
+ sort.csort = p.first
+ return (sort, p.second)
+
+
def isUninterpretedSortValue(self):
""":return: True iff this term is a value from an uninterpreted sort."""
return self.cterm.isUninterpretedSortValue()
with pytest.raises(RuntimeError):
su.getSequenceValue()
+def test_get_cardinality_constraint(solver):
+ su = solver.mkUninterpretedSort("u")
+ t = solver.mkCardinalityConstraint(su, 3)
+ assert t.isCardinalityConstraint()
+ cc = t.getCardinalityConstraint()
+ assert cc[0] == su
+ assert cc[1] == 3
+ x = solver.mkConst(solver.getIntegerSort(), "x")
+ assert not x.isCardinalityConstraint()
+ with pytest.raises(RuntimeError):
+ x.getCardinalityConstraint()
+ nullt = cvc5.Term(solver)
+ with pytest.raises(RuntimeError):
+ nullt.isCardinalityConstraint()
+
+
def test_term_scoped_to_string(solver):
intsort = solver.getIntegerSort()