New C++ API: Add tests for sort functions of solver object. (#2752)
authorAina Niemetz <aina.niemetz@gmail.com>
Thu, 13 Dec 2018 21:17:22 +0000 (13:17 -0800)
committerGitHub <noreply@github.com>
Thu, 13 Dec 2018 21:17:22 +0000 (13:17 -0800)
src/api/cvc4cpp.cpp
test/unit/api/solver_black.h

index b4d3b013dfcd86aa32b1805a8a3c00b46dda314e..cadad4eff83e2953a398821b949534204e24184e 100644 (file)
@@ -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);
 }
 
index 7527a5c55573414ef2c3f5dc0bf8f1cecfa398e7..b0249b8a064d9a77e4a1cf5391e67952e7793974 100644 (file)
@@ -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<std::pair<std::string, Sort>> 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<std::pair<std::string, Sort>> 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()}));