Files
cvc5/test/unit/api/python/test_result.py
Andrew Reynolds e579c9094e Add conflict, unsoundness and negation tracking to assertion pipeline (#10141)
This allows us to terminate quickly during preprocessing if a false assertion is encountered.

The other flags allow more generic handling of how to post-process results of check-sat.
2023-11-07 14:56:21 -06:00

88 lines
2.5 KiB
Python

###############################################################################
# Top contributors (to current version):
# Yoni Zohar, Gereon Kremer, Andrew Reynolds
#
# This file is part of the cvc5 project.
#
# Copyright (c) 2009-2023 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 cvc5
from cvc5 import Result
from cvc5 import Kind, UnknownExplanation
@pytest.fixture
def solver():
return cvc5.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.isUnknown()
u_sort = solver.mkUninterpretedSort("u")
x = solver.mkConst(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.mkConst(u_sort, "x")
solver.assertFormula(x.eqTerm(x))
res2 = solver.checkSat()
res3 = solver.checkSat()
res = Result()
assert res != res2
res = res2
assert res == res2
assert res3 == res2
assert str(res) == "sat"
def test_is_sat(solver):
u_sort = solver.mkUninterpretedSort("u")
x = solver.mkConst(u_sort, "x")
solver.assertFormula(x.eqTerm(x))
res = solver.checkSat()
assert res.isSat()
assert not res.isUnknown()
def test_is_unsat(solver):
u_sort = solver.mkUninterpretedSort("u")
x = solver.mkConst(u_sort, "x")
solver.assertFormula(x.eqTerm(x).notTerm())
res = solver.checkSat()
assert res.isUnsat()
assert not res.isUnknown()
def test_is_sat_unknown(solver):
solver.setLogic("QF_NIA")
solver.setOption("incremental", "false")
solver.setOption("solve-real-as-int", "true")
real_sort = solver.getRealSort()
x = solver.mkConst(real_sort, "x")
solver.assertFormula(solver.mkTerm(Kind.LT, solver.mkReal("0.0"), x))
solver.assertFormula(solver.mkTerm(Kind.LT, x, solver.mkReal("1.0")))
res = solver.checkSat()
assert not res.isSat()
assert res.isUnknown()
ue = res.getUnknownExplanation()
assert ue == UnknownExplanation.UNKNOWN_REASON
assert str(ue) == "UnknownExplanation.UNKNOWN_REASON"