2021-04-12 12:31:43 -07:00
|
|
|
|
###############################################################################
|
|
|
|
|
|
# Top contributors (to current version):
|
|
|
|
|
|
# Makai Mann, Andres Noetzli, Mudathir Mohamed
|
|
|
|
|
|
#
|
|
|
|
|
|
# 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.
|
|
|
|
|
|
# #############################################################################
|
2020-12-02 19:55:00 -08:00
|
|
|
|
##
|
2021-04-12 12:31:43 -07:00
|
|
|
|
|
2020-09-22 11:58:03 -07:00
|
|
|
|
from fractions import Fraction
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
2021-04-21 10:21:34 -07:00
|
|
|
|
import pycvc5
|
|
|
|
|
|
from pycvc5 import kinds
|
2020-09-22 11:58:03 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def testGetBool():
|
2021-04-21 10:21:34 -07:00
|
|
|
|
solver = pycvc5.Solver()
|
2020-09-22 11:58:03 -07:00
|
|
|
|
t = solver.mkTrue()
|
|
|
|
|
|
f = solver.mkFalse()
|
|
|
|
|
|
assert t.toPythonObj() == True
|
|
|
|
|
|
assert f.toPythonObj() == False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def testGetInt():
|
2021-04-21 10:21:34 -07:00
|
|
|
|
solver = pycvc5.Solver()
|
2020-10-29 13:26:51 -05:00
|
|
|
|
two = solver.mkInteger(2)
|
2020-09-22 11:58:03 -07:00
|
|
|
|
assert two.toPythonObj() == 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def testGetReal():
|
2021-04-21 10:21:34 -07:00
|
|
|
|
solver = pycvc5.Solver()
|
2020-09-22 11:58:03 -07:00
|
|
|
|
half = solver.mkReal("1/2")
|
|
|
|
|
|
assert half.toPythonObj() == Fraction(1, 2)
|
|
|
|
|
|
|
|
|
|
|
|
neg34 = solver.mkReal("-3/4")
|
|
|
|
|
|
assert neg34.toPythonObj() == Fraction(-3, 4)
|
|
|
|
|
|
|
2020-10-29 13:26:51 -05:00
|
|
|
|
neg1 = solver.mkInteger("-1")
|
2020-09-22 11:58:03 -07:00
|
|
|
|
assert neg1.toPythonObj() == -1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def testGetBV():
|
2021-04-21 10:21:34 -07:00
|
|
|
|
solver = pycvc5.Solver()
|
2020-09-22 11:58:03 -07:00
|
|
|
|
three = solver.mkBitVector(8, 3)
|
|
|
|
|
|
assert three.toPythonObj() == 3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def testGetArray():
|
2021-04-21 10:21:34 -07:00
|
|
|
|
solver = pycvc5.Solver()
|
2020-09-22 11:58:03 -07:00
|
|
|
|
arrsort = solver.mkArraySort(solver.getRealSort(), solver.getRealSort())
|
2020-10-29 13:26:51 -05:00
|
|
|
|
zero_array = solver.mkConstArray(arrsort, solver.mkInteger(0))
|
|
|
|
|
|
stores = solver.mkTerm(kinds.Store, zero_array, solver.mkInteger(1), solver.mkInteger(2))
|
|
|
|
|
|
stores = solver.mkTerm(kinds.Store, stores, solver.mkInteger(2), solver.mkInteger(3))
|
|
|
|
|
|
stores = solver.mkTerm(kinds.Store, stores, solver.mkInteger(4), solver.mkInteger(5))
|
2020-09-22 11:58:03 -07:00
|
|
|
|
|
|
|
|
|
|
array_dict = stores.toPythonObj()
|
|
|
|
|
|
|
|
|
|
|
|
assert array_dict[1] == 2
|
|
|
|
|
|
assert array_dict[2] == 3
|
|
|
|
|
|
assert array_dict[4] == 5
|
|
|
|
|
|
# an index that wasn't stored at should give zero
|
|
|
|
|
|
assert array_dict[8] == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def testGetSymbol():
|
2021-04-21 10:21:34 -07:00
|
|
|
|
solver = pycvc5.Solver()
|
2020-10-29 13:26:51 -05:00
|
|
|
|
solver.mkConst(solver.getBooleanSort(), "x")
|
2020-09-22 17:41:09 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def testGetString():
|
2021-04-21 10:21:34 -07:00
|
|
|
|
solver = pycvc5.Solver()
|
2020-09-22 17:41:09 -07:00
|
|
|
|
|
|
|
|
|
|
s1 = '"test\n"😃\\u{a}'
|
|
|
|
|
|
t1 = solver.mkString(s1)
|
|
|
|
|
|
assert s1 == t1.toPythonObj()
|
|
|
|
|
|
|
2021-04-21 10:21:34 -07:00
|
|
|
|
s2 = '❤️cvc5❤️'
|
2020-09-22 17:41:09 -07:00
|
|
|
|
t2 = solver.mkString(s2)
|
|
|
|
|
|
assert s2 == t2.toPythonObj()
|