File: api_result_black.cpp

package info (click to toggle)
cvc5 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 87,260 kB
  • sloc: cpp: 383,850; java: 12,207; python: 12,090; sh: 5,679; ansic: 4,729; lisp: 763; perl: 208; makefile: 38
file content (109 lines) | stat: -rw-r--r-- 3,250 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/******************************************************************************
 * Top contributors (to current version):
 *   Aina Niemetz, Gereon Kremer, Andrew Reynolds
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2025 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.
 * ****************************************************************************
 *
 * Black box testing of the Result class
 */

#include "test_api.h"

namespace cvc5::internal {

namespace test {

class TestApiBlackResult : public TestApi
{
};

TEST_F(TestApiBlackResult, isNull)
{
  cvc5::Result res_null;
  ASSERT_TRUE(res_null.isNull());
  ASSERT_FALSE(res_null.isSat());
  ASSERT_FALSE(res_null.isUnsat());
  ASSERT_FALSE(res_null.isUnknown());
  Sort u_sort = d_tm.mkUninterpretedSort("u");
  Term x = d_tm.mkConst(u_sort, "x");
  d_solver->assertFormula(x.eqTerm(x));
  cvc5::Result res = d_solver->checkSat();
  ASSERT_FALSE(res.isNull());
}

TEST_F(TestApiBlackResult, equalHash)
{
  Sort u_sort = d_tm.mkUninterpretedSort("u");
  Term x = d_tm.mkConst(u_sort, "x");
  d_solver->assertFormula(x.eqTerm(x));
  cvc5::Result res;
  cvc5::Result res2 = d_solver->checkSat();
  cvc5::Result res3 = d_solver->checkSat();
  ASSERT_NE(res, res2);
  res = res2;
  ASSERT_EQ(res, res2);
  ASSERT_EQ(res3, res2);
  {
    std::stringstream ss;
    ss << res;
    ASSERT_EQ(res.toString(), "sat");
    ASSERT_EQ(res.toString(), ss.str());
  }
  ASSERT_EQ(std::hash<cvc5::Result>{}(res), std::hash<cvc5::Result>{}(res2));
  ASSERT_NE(std::hash<cvc5::Result>{}(cvc5::Result()),
            std::hash<cvc5::Result>{}(res2));
  (void)std::hash<cvc5::Result>{}(cvc5::Result());
}

TEST_F(TestApiBlackResult, isSat)
{
  Sort u_sort = d_tm.mkUninterpretedSort("u");
  Term x = d_tm.mkConst(u_sort, "x");
  d_solver->assertFormula(x.eqTerm(x));
  cvc5::Result res = d_solver->checkSat();
  ASSERT_TRUE(res.isSat());
  ASSERT_FALSE(res.isUnsat());
  ASSERT_FALSE(res.isUnknown());
}

TEST_F(TestApiBlackResult, isUnsat)
{
  Sort u_sort = d_tm.mkUninterpretedSort("u");
  Term x = d_tm.mkConst(u_sort, "x");
  d_solver->assertFormula(x.eqTerm(x).notTerm());
  cvc5::Result res = d_solver->checkSat();
  ASSERT_FALSE(res.isSat());
  ASSERT_TRUE(res.isUnsat());
  ASSERT_FALSE(res.isUnknown());
}

TEST_F(TestApiBlackResult, isUnknown)
{
  d_solver->setLogic("QF_NIA");
  d_solver->setOption("incremental", "false");
  d_solver->setOption("solve-real-as-int", "true");
  Sort real_sort = d_tm.getRealSort();
  Term x = d_tm.mkConst(real_sort, "x");
  d_solver->assertFormula(d_tm.mkTerm(Kind::LT, {d_tm.mkReal("0.0"), x}));
  d_solver->assertFormula(d_tm.mkTerm(Kind::LT, {x, d_tm.mkReal("1.0")}));
  cvc5::Result res = d_solver->checkSat();
  ASSERT_FALSE(res.isSat());
  ASSERT_FALSE(res.isUnsat());
  ASSERT_TRUE(res.isUnknown());
  cvc5::UnknownExplanation ue = res.getUnknownExplanation();
  ASSERT_EQ(ue, cvc5::UnknownExplanation::INCOMPLETE);
  {
    std::stringstream ss;
    ss << ue;
    ASSERT_EQ(ss.str(), "INCOMPLETE");
  }
}

}  // namespace test
}  // namespace cvc5::internal