{
CVC5_API_TRY_CATCH_BEGIN;
CVC5_API_CHECK_NOT_NULL;
+ CVC5_API_CHECK(!d_dtype->isParametric())
+ << "Invalid call to 'isFinite()', expected non-parametric Datatype";
//////// all checks before this line
// we assume that finite model finding is disabled by passing false as the
// second argument
ASSERT_TRUE(pairIntInt.isSubsortOf(pairIntInt));
}
+TEST_F(TestApiBlackDatatype, isFinite)
+{
+ DatatypeDecl dtypedecl = d_solver.mkDatatypeDecl("dt", {});
+ DatatypeConstructorDecl ctordecl = d_solver.mkDatatypeConstructorDecl("cons");
+ ctordecl.addSelector("sel", d_solver.getBooleanSort());
+ dtypedecl.addConstructor(ctordecl);
+ Sort dtype = d_solver.mkDatatypeSort(dtypedecl);
+ ASSERT_TRUE(dtype.getDatatype().isFinite());
+
+ Sort p = d_solver.mkParamSort("p1");
+ DatatypeDecl pdtypedecl = d_solver.mkDatatypeDecl("dt", {p});
+ DatatypeConstructorDecl pctordecl =
+ d_solver.mkDatatypeConstructorDecl("cons");
+ pctordecl.addSelector("sel", p);
+ pdtypedecl.addConstructor(pctordecl);
+ Sort pdtype = d_solver.mkDatatypeSort(pdtypedecl);
+ ASSERT_THROW(pdtype.getDatatype().isFinite(), CVC5ApiException);
+}
+
TEST_F(TestApiBlackDatatype, datatypeSimplyRec)
{
/* Create mutual datatypes corresponding to this definition block:
assertTrue(pairIntInt.isSubsortOf(pairIntInt));
}
+ @Test void datatypeIsFinite() throws CVC5ApiException
+ {
+ List<Sort> v = new ArrayList<>();
+ DatatypeDecl dtypedecl = d_solver.mkDatatypeDecl("dt", v);
+ DatatypeConstructorDecl ctordecl = d_solver.mkDatatypeConstructorDecl("cons");
+ ctordecl.addSelector("sel", d_solver.getBooleanSort());
+ dtypedecl.addConstructor(ctordecl);
+ Sort dtype = d_solver.mkDatatypeSort(dtypedecl);
+ assertTrue(dtype.getDatatype().isFinite());
+
+ Sort p = d_solver.mkParamSort("p1");
+ v.add(p);
+ DatatypeDecl pdtypedecl = d_solver.mkDatatypeDecl("dt", v);
+ DatatypeConstructorDecl pctordecl = d_solver.mkDatatypeConstructorDecl("cons");
+ pctordecl.addSelector("sel", p);
+ pdtypedecl.addConstructor(pctordecl);
+ Sort pdtype = d_solver.mkDatatypeSort(pdtypedecl);
+ assertThrows(CVC5ApiException.class, () -> pdtype.getDatatype().isFinite());
+ }
+
@Test void datatypeSimplyRec() throws CVC5ApiException
{
/* Create mutual datatypes corresponding to this definition block:
v.append(t1)
v.append(t2)
pairSpec = solver.mkDatatypeDecl("pair", v)
-
+
mkpair = solver.mkDatatypeConstructorDecl("mk-pair")
mkpair.addSelector("first", t1)
mkpair.addSelector("second", t2)
assert not pairRealInt.isSubsortOf(pairIntInt)
assert pairIntInt.isSubsortOf(pairIntInt)
+def test_is_finite(solver):
+ dtypedecl = solver.mkDatatypeDecl("dt", [])
+ ctordecl = solver.mkDatatypeConstructorDecl("cons")
+ ctordecl.addSelector("sel", solver.getBooleanSort())
+ dtypedecl.addConstructor(ctordecl)
+ dtype = solver.mkDatatypeSort(dtypedecl)
+ assert dtype.getDatatype().isFinite()
+
+ p = solver.mkParamSort("p1")
+ pdtypedecl = solver.mkDatatypeDecl("dt", [p])
+ pctordecl = solver.mkDatatypeConstructorDecl("cons")
+ pctordecl.addSelector("sel", p)
+ pdtypedecl.addConstructor(pctordecl)
+ pdtype = solver.mkDatatypeSort(pdtypedecl)
+ with pytest.raises(RuntimeError):
+ pdtype.getDatatype().isFinite()
def test_datatype_simply_rec(solver):
# Create mutual datatypes corresponding to this definition block: