Add missing tests for some corners of the API (#8688)
[cvc5.git] / test / unit / api / cpp / synth_result_black.cpp
index d2aebdbc46d898d2d5b70c681ce939b28f462ec4..c902fbbc9479084127ec06fa317a9555af9d3cc2 100644 (file)
@@ -1,10 +1,10 @@
 /******************************************************************************
  * Top contributors (to current version):
- *   Andrew Reynolds
+ *   Andrew Reynolds, Mathias Preiner, Aina Niemetz
  *
  * This file is part of the cvc5 project.
  *
- * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
+ * Copyright (c) 2009-2022 by the authors listed in the file AUTHORS
  * in the top-level source directory and their institutional affiliations.
  * All rights reserved.  See the file COPYING in the top-level source
  * directory for licensing information.
@@ -15,9 +15,7 @@
 
 #include "test_api.h"
 
-namespace cvc5 {
-
-using namespace api;
+namespace cvc5::internal {
 
 namespace test {
 
@@ -27,12 +25,54 @@ class TestApiBlackSynthResult : public TestApi
 
 TEST_F(TestApiBlackSynthResult, isNull)
 {
-  cvc5::api::SynthResult res_null;
+  cvc5::SynthResult res_null;
   ASSERT_TRUE(res_null.isNull());
   ASSERT_FALSE(res_null.hasSolution());
   ASSERT_FALSE(res_null.hasNoSolution());
   ASSERT_FALSE(res_null.isUnknown());
 }
 
+TEST_F(TestApiBlackSynthResult, hasSolution)
+{
+  d_solver.setOption("sygus", "true");
+  Term f = d_solver.synthFun("f", {}, d_solver.getBooleanSort());
+  Term boolTerm = d_solver.mkTrue();
+  d_solver.addSygusConstraint(boolTerm);
+  cvc5::SynthResult res = d_solver.checkSynth();
+  ASSERT_FALSE(res.isNull());
+  ASSERT_TRUE(res.hasSolution());
+  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)
+{
+  // note that we never return synth result for which hasNoSolution is true
+  // currently
+  cvc5::SynthResult res_null;
+  ASSERT_FALSE(res_null.hasNoSolution());
+}
+
+TEST_F(TestApiBlackSynthResult, isUnknown)
+{
+  d_solver.setOption("sygus", "true");
+  Term f = d_solver.synthFun("f", {}, d_solver.getBooleanSort());
+  Term boolTerm = d_solver.mkFalse();
+  d_solver.addSygusConstraint(boolTerm);
+  cvc5::SynthResult res = d_solver.checkSynth();
+  // currently isUnknown, could also return hasNoSolution when support for
+  // infeasibility of sygus conjectures is added.
+  ASSERT_FALSE(res.isNull());
+  ASSERT_FALSE(res.hasSolution());
+  ASSERT_FALSE(res.hasNoSolution());
+  ASSERT_TRUE(res.isUnknown());
+}
+
 }  // namespace test
-}  // namespace cvc5
+}  // namespace cvc5::internal