File: test_result.py

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 (90 lines) | stat: -rw-r--r-- 2,574 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
###############################################################################
# Top contributors (to current version):
#   Yoni Zohar, Aina Niemetz, 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.
# #############################################################################
#
# 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 tm():
    return cvc5.TermManager()
@pytest.fixture
def solver(tm):
    return cvc5.Solver(tm)


def test_is_null(tm, solver):
    res_null = Result()
    assert res_null.isNull()
    assert not res_null.isSat()
    assert not res_null.isUnsat()
    assert not res_null.isUnknown()
    u_sort = tm.mkUninterpretedSort("u")
    x = tm.mkConst(u_sort, "x")
    solver.assertFormula(x.eqTerm(x))
    res = solver.checkSat()
    assert not res.isNull()


def test_eq(tm, solver):
    u_sort = tm.mkUninterpretedSort("u")
    x = tm.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(tm, solver):
    u_sort = tm.mkUninterpretedSort("u")
    x = tm.mkConst(u_sort, "x")
    solver.assertFormula(x.eqTerm(x))
    res = solver.checkSat()
    assert res.isSat()
    assert not res.isUnknown()


def test_is_unsat(tm, solver):
    u_sort = tm.mkUninterpretedSort("u")
    x = tm.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(tm, solver):
    solver.setLogic("QF_NIA")
    solver.setOption("incremental", "false")
    solver.setOption("solve-real-as-int", "true")
    real_sort = tm.getRealSort()
    x = tm.mkConst(real_sort, "x")
    solver.assertFormula(tm.mkTerm(Kind.LT, tm.mkReal("0.0"), x))
    solver.assertFormula(tm.mkTerm(Kind.LT, x, tm.mkReal("1.0")))
    res = solver.checkSat()
    assert not res.isSat()
    assert res.isUnknown()
    ue = res.getUnknownExplanation()
    assert ue == UnknownExplanation.INCOMPLETE
    assert str(ue) == "UnknownExplanation.INCOMPLETE"