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
110
111
112
113
114
|
###############################################################################
# Top contributors (to current version):
# Yoni Zohar
#
# This file is part of the cvc5 project.
#
# Copyright (c) 2009-2021 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.
# #############################################################################
#
# Unit tests for result API.
#
# Obtained by translating test/unit/api/result_black.cpp
##
import pytest
import pycvc5
from pycvc5 import Result
from pycvc5 import UnknownExplanation
@pytest.fixture
def solver():
return pycvc5.Solver()
def test_is_null(solver):
res_null = Result(solver)
assert res_null.isNull()
assert not res_null.isSat()
assert not res_null.isUnsat()
assert not res_null.isSatUnknown()
assert not res_null.isEntailed()
assert not res_null.isNotEntailed()
assert not res_null.isEntailmentUnknown()
u_sort = solver.mkUninterpretedSort("u")
x = solver.mkVar(u_sort, "x")
solver.assertFormula(x.eqTerm(x))
res = solver.checkSat()
assert not res.isNull()
def test_eq(solver):
u_sort = solver.mkUninterpretedSort("u")
x = solver.mkVar(u_sort, "x")
solver.assertFormula(x.eqTerm(x))
res2 = solver.checkSat()
res3 = solver.checkSat()
res = res2
assert res == res2
assert res3 == res2
def test_is_sat(solver):
u_sort = solver.mkUninterpretedSort("u")
x = solver.mkVar(u_sort, "x")
solver.assertFormula(x.eqTerm(x))
res = solver.checkSat()
assert res.isSat()
assert not res.isSatUnknown()
def test_is_unsat(solver):
u_sort = solver.mkUninterpretedSort("u")
x = solver.mkVar(u_sort, "x")
solver.assertFormula(x.eqTerm(x).notTerm())
res = solver.checkSat()
assert res.isUnsat()
assert not res.isSatUnknown()
def test_is_sat_unknown(solver):
solver.setLogic("QF_NIA")
solver.setOption("incremental", "false")
solver.setOption("solve-int-as-bv", "32")
int_sort = solver.getIntegerSort()
x = solver.mkVar(int_sort, "x")
solver.assertFormula(x.eqTerm(x).notTerm())
res = solver.checkSat()
assert not res.isSat()
assert res.isSatUnknown()
def test_is_entailed(solver):
solver.setOption("incremental", "true")
u_sort = solver.mkUninterpretedSort("u")
x = solver.mkConst(u_sort, "x")
y = solver.mkConst(u_sort, "y")
a = x.eqTerm(y).notTerm()
b = x.eqTerm(y)
solver.assertFormula(a)
entailed = solver.checkEntailed(a)
assert entailed.isEntailed()
assert not entailed.isEntailmentUnknown()
not_entailed = solver.checkEntailed(b)
assert not_entailed.isNotEntailed()
assert not not_entailed.isEntailmentUnknown()
def test_is_entailment_unknown(solver):
solver.setLogic("QF_NIA")
solver.setOption("incremental", "false")
solver.setOption("solve-int-as-bv", "32")
int_sort = solver.getIntegerSort()
x = solver.mkVar(int_sort, "x")
solver.assertFormula(x.eqTerm(x).notTerm())
res = solver.checkEntailed(x.eqTerm(x))
assert not res.isEntailed()
assert res.isEntailmentUnknown()
print(type(pycvc5.RoundTowardZero))
print(type(pycvc5.UnknownReason))
assert res.getUnknownExplanation() == pycvc5.UnknownReason
|