From bc59b160f3890f68c497dde13ff54c194f476eb4 Mon Sep 17 00:00:00 2001 From: Aina Niemetz Date: Thu, 13 Dec 2018 13:17:22 -0800 Subject: [PATCH] New C++ API: Add tests for sort functions of solver object. (#2752) --- src/api/cvc4cpp.cpp | 1 + test/unit/api/solver_black.h | 99 ++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/src/api/cvc4cpp.cpp b/src/api/cvc4cpp.cpp index b4d3b013d..cadad4eff 100644 --- a/src/api/cvc4cpp.cpp +++ b/src/api/cvc4cpp.cpp @@ -1750,6 +1750,7 @@ Sort Solver::mkUninterpretedSort(const std::string& symbol) const Sort Solver::mkSortConstructorSort(const std::string& symbol, size_t arity) const { + CVC4_API_ARG_CHECK_EXPECTED(arity > 0, arity) << "an arity > 0"; return d_exprMgr->mkSortConstructor(symbol, arity); } diff --git a/test/unit/api/solver_black.h b/test/unit/api/solver_black.h index 7527a5c55..b0249b8a0 100644 --- a/test/unit/api/solver_black.h +++ b/test/unit/api/solver_black.h @@ -26,16 +26,31 @@ class SolverBlack : public CxxTest::TestSuite void setUp() override; void tearDown() override; + void testGetBooleanSort(); + void testGetIntegerSort(); + void testGetRealSort(); + void testGetRegExpSort(); + void testGetStringSort(); + void testGetRoundingmodeSort(); + + void testMkArraySort(); void testMkBitVectorSort(); void testMkFloatingPointSort(); void testMkDatatypeSort(); void testMkFunctionSort(); + void testMkParamSort(); void testMkPredicateSort(); + void testMkRecordSort(); + void testMkSetSort(); + void testMkSortConstructorSort(); + void testMkUninterpretedSort(); void testMkTupleSort(); + void testDeclareFun(); void testDefineFun(); void testDefineFunRec(); void testDefineFunsRec(); + void testMkRegexpEmpty(); void testMkRegexpSigma(); @@ -47,6 +62,53 @@ void SolverBlack::setUp() {} void SolverBlack::tearDown() {} +void SolverBlack::testGetBooleanSort() +{ + TS_ASSERT_THROWS_NOTHING(d_solver.getBooleanSort()); +} + +void SolverBlack::testGetIntegerSort() +{ + TS_ASSERT_THROWS_NOTHING(d_solver.getIntegerSort()); +} + +void SolverBlack::testGetRealSort() +{ + TS_ASSERT_THROWS_NOTHING(d_solver.getRealSort()); +} + +void SolverBlack::testGetRegExpSort() +{ + TS_ASSERT_THROWS_NOTHING(d_solver.getRegExpSort()); +} + +void SolverBlack::testGetStringSort() +{ + TS_ASSERT_THROWS_NOTHING(d_solver.getStringSort()); +} + +void SolverBlack::testGetRoundingmodeSort() +{ + TS_ASSERT_THROWS_NOTHING(d_solver.getRoundingmodeSort()); +} + +void SolverBlack::testMkArraySort() +{ + Sort boolSort = d_solver.getBooleanSort(); + Sort intSort = d_solver.getIntegerSort(); + Sort realSort = d_solver.getRealSort(); + Sort bvSort = d_solver.mkBitVectorSort(32); + Sort fpSort = d_solver.mkFloatingPointSort(3, 5); + TS_ASSERT_THROWS_NOTHING(d_solver.mkArraySort(boolSort, boolSort)); + TS_ASSERT_THROWS_NOTHING(d_solver.mkArraySort(intSort, intSort)); + TS_ASSERT_THROWS_NOTHING(d_solver.mkArraySort(realSort, realSort)); + TS_ASSERT_THROWS_NOTHING(d_solver.mkArraySort(bvSort, bvSort)); + TS_ASSERT_THROWS_NOTHING(d_solver.mkArraySort(fpSort, fpSort)); + TS_ASSERT_THROWS_NOTHING(d_solver.mkArraySort(boolSort, intSort)); + TS_ASSERT_THROWS_NOTHING(d_solver.mkArraySort(realSort, bvSort)); + TS_ASSERT_THROWS_NOTHING(d_solver.mkArraySort(bvSort, fpSort)); +} + void SolverBlack::testMkBitVectorSort() { TS_ASSERT_THROWS_NOTHING(d_solver.mkBitVectorSort(32)); @@ -99,6 +161,12 @@ void SolverBlack::testMkFunctionSort() CVC4ApiException&); } +void SolverBlack::testMkParamSort() +{ + TS_ASSERT_THROWS_NOTHING(d_solver.mkParamSort("T")); + TS_ASSERT_THROWS_NOTHING(d_solver.mkParamSort("")); +} + void SolverBlack::testMkPredicateSort() { TS_ASSERT_THROWS_NOTHING( @@ -111,6 +179,37 @@ void SolverBlack::testMkPredicateSort() CVC4ApiException&); } +void SolverBlack::testMkRecordSort() +{ + std::vector> fields = { + std::make_pair("b", d_solver.getBooleanSort()), + std::make_pair("bv", d_solver.mkBitVectorSort(8)), + std::make_pair("i", d_solver.getIntegerSort())}; + std::vector> empty; + TS_ASSERT_THROWS_NOTHING(d_solver.mkRecordSort(fields)); + TS_ASSERT_THROWS_NOTHING(d_solver.mkRecordSort(empty)); +} + +void SolverBlack::testMkSetSort() +{ + TS_ASSERT_THROWS_NOTHING(d_solver.mkSetSort(d_solver.getBooleanSort())); + TS_ASSERT_THROWS_NOTHING(d_solver.mkSetSort(d_solver.getIntegerSort())); + TS_ASSERT_THROWS_NOTHING(d_solver.mkSetSort(d_solver.mkBitVectorSort(4))); +} + +void SolverBlack::testMkUninterpretedSort() +{ + TS_ASSERT_THROWS_NOTHING(d_solver.mkUninterpretedSort("u")); + TS_ASSERT_THROWS_NOTHING(d_solver.mkUninterpretedSort("")); +} + +void SolverBlack::testMkSortConstructorSort() +{ + TS_ASSERT_THROWS_NOTHING(d_solver.mkSortConstructorSort("s", 2)); + TS_ASSERT_THROWS_NOTHING(d_solver.mkSortConstructorSort("", 2)); + TS_ASSERT_THROWS(d_solver.mkSortConstructorSort("", 0), CVC4ApiException&); +} + void SolverBlack::testMkTupleSort() { TS_ASSERT_THROWS_NOTHING(d_solver.mkTupleSort({d_solver.getIntegerSort()})); -- 2.30.2