2021-05-13 20:15:21 -05:00
|
|
|
/******************************************************************************
|
|
|
|
|
* Top contributors (to current version):
|
2025-01-23 09:54:20 -08:00
|
|
|
* Mudathir Mohamed, Aina Niemetz, Andrew Reynolds
|
2021-05-13 20:15:21 -05:00
|
|
|
*
|
|
|
|
|
* This file is part of the cvc5 project.
|
|
|
|
|
*
|
2025-01-23 09:54:20 -08:00
|
|
|
* Copyright (c) 2009-2025 by the authors listed in the file AUTHORS
|
2021-05-13 20:15:21 -05:00
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-22 18:00:06 -05:00
|
|
|
package tests;
|
2021-05-13 20:15:21 -05:00
|
|
|
|
2023-11-07 14:56:21 -06:00
|
|
|
import static io.github.cvc5.Kind.*;
|
2021-05-13 20:15:21 -05:00
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
|
|
2022-03-30 21:09:03 -07:00
|
|
|
import io.github.cvc5.*;
|
2021-05-13 20:15:21 -05:00
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
class ResultTest
|
|
|
|
|
{
|
2024-04-02 09:42:06 -07:00
|
|
|
private TermManager d_tm;
|
2021-05-13 20:15:21 -05:00
|
|
|
private Solver d_solver;
|
|
|
|
|
|
2022-03-30 16:58:08 -05:00
|
|
|
@BeforeEach
|
|
|
|
|
void setUp()
|
2021-05-13 20:15:21 -05:00
|
|
|
{
|
2024-04-02 09:42:06 -07:00
|
|
|
d_tm = new TermManager();
|
|
|
|
|
d_solver = new Solver(d_tm);
|
2021-05-13 20:15:21 -05:00
|
|
|
}
|
|
|
|
|
|
2022-03-30 16:58:08 -05:00
|
|
|
@AfterEach
|
|
|
|
|
void tearDown()
|
2021-11-03 16:32:10 -05:00
|
|
|
{
|
2022-10-04 12:06:02 -05:00
|
|
|
Context.deletePointers();
|
2021-11-03 16:32:10 -05:00
|
|
|
}
|
|
|
|
|
|
2022-03-30 16:58:08 -05:00
|
|
|
@Test
|
|
|
|
|
void isNull()
|
2021-05-13 20:15:21 -05:00
|
|
|
{
|
2022-10-04 12:06:02 -05:00
|
|
|
Result res_null = new Result();
|
2021-05-13 20:15:21 -05:00
|
|
|
assertTrue(res_null.isNull());
|
|
|
|
|
assertFalse(res_null.isSat());
|
|
|
|
|
assertFalse(res_null.isUnsat());
|
2022-03-21 20:27:20 -05:00
|
|
|
assertFalse(res_null.isUnknown());
|
2024-04-02 09:42:06 -07:00
|
|
|
Sort u_sort = d_tm.mkUninterpretedSort("u");
|
|
|
|
|
Term x = d_tm.mkConst(u_sort, "x");
|
2021-05-13 20:15:21 -05:00
|
|
|
d_solver.assertFormula(x.eqTerm(x));
|
|
|
|
|
Result res = d_solver.checkSat();
|
|
|
|
|
assertFalse(res.isNull());
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-30 16:58:08 -05:00
|
|
|
@Test
|
2024-07-10 10:54:35 -07:00
|
|
|
void equalHash()
|
2021-05-13 20:15:21 -05:00
|
|
|
{
|
2024-04-02 09:42:06 -07:00
|
|
|
Sort u_sort = d_tm.mkUninterpretedSort();
|
|
|
|
|
Term x = d_tm.mkConst(u_sort, "x");
|
2021-05-13 20:15:21 -05:00
|
|
|
d_solver.assertFormula(x.eqTerm(x));
|
2022-04-28 17:47:10 -07:00
|
|
|
Result res = null;
|
2021-05-13 20:15:21 -05:00
|
|
|
Result res2 = d_solver.checkSat();
|
|
|
|
|
Result res3 = d_solver.checkSat();
|
|
|
|
|
res = res2;
|
2024-07-10 10:54:35 -07:00
|
|
|
assertTrue(res.equals(res2));
|
|
|
|
|
assertTrue(res3.equals(res2));
|
2022-04-28 17:47:10 -07:00
|
|
|
assertEquals(res.toString(), "sat");
|
2024-07-10 10:54:35 -07:00
|
|
|
assertEquals(res.hashCode(), res2.hashCode());
|
|
|
|
|
assertEquals(res3.hashCode(), res2.hashCode());
|
2021-05-13 20:15:21 -05:00
|
|
|
}
|
|
|
|
|
|
2022-03-30 16:58:08 -05:00
|
|
|
@Test
|
|
|
|
|
void isSat()
|
2021-05-13 20:15:21 -05:00
|
|
|
{
|
2024-04-02 09:42:06 -07:00
|
|
|
Sort u_sort = d_tm.mkUninterpretedSort("u");
|
|
|
|
|
Term x = d_tm.mkConst(u_sort, "x");
|
2021-05-13 20:15:21 -05:00
|
|
|
d_solver.assertFormula(x.eqTerm(x));
|
|
|
|
|
Result res = d_solver.checkSat();
|
|
|
|
|
assertTrue(res.isSat());
|
2022-03-21 20:27:20 -05:00
|
|
|
assertFalse(res.isUnknown());
|
2021-05-13 20:15:21 -05:00
|
|
|
}
|
|
|
|
|
|
2022-03-30 16:58:08 -05:00
|
|
|
@Test
|
|
|
|
|
void isUnsat()
|
2021-05-13 20:15:21 -05:00
|
|
|
{
|
2024-04-02 09:42:06 -07:00
|
|
|
Sort u_sort = d_tm.mkUninterpretedSort();
|
|
|
|
|
Term x = d_tm.mkConst(u_sort, "x");
|
2021-05-13 20:15:21 -05:00
|
|
|
d_solver.assertFormula(x.eqTerm(x).notTerm());
|
|
|
|
|
Result res = d_solver.checkSat();
|
|
|
|
|
assertTrue(res.isUnsat());
|
2022-03-21 20:27:20 -05:00
|
|
|
assertFalse(res.isUnknown());
|
2021-05-13 20:15:21 -05:00
|
|
|
}
|
|
|
|
|
|
2022-03-30 16:58:08 -05:00
|
|
|
@Test
|
|
|
|
|
void isUnknown() throws CVC5ApiException
|
2022-03-29 22:15:58 -05:00
|
|
|
{
|
2021-05-13 20:15:21 -05:00
|
|
|
d_solver.setLogic("QF_NIA");
|
|
|
|
|
d_solver.setOption("incremental", "false");
|
2023-11-07 14:56:21 -06:00
|
|
|
d_solver.setOption("solve-real-as-int", "true");
|
2024-04-02 09:42:06 -07:00
|
|
|
Sort real_sort = d_tm.getIntegerSort();
|
|
|
|
|
Term x = d_tm.mkConst(real_sort, "x");
|
|
|
|
|
d_solver.assertFormula(d_tm.mkTerm(LT, d_tm.mkReal("0.0"), x));
|
|
|
|
|
d_solver.assertFormula(d_tm.mkTerm(LT, x, d_tm.mkReal("1.0")));
|
2021-05-13 20:15:21 -05:00
|
|
|
Result res = d_solver.checkSat();
|
|
|
|
|
assertFalse(res.isSat());
|
2022-03-21 20:27:20 -05:00
|
|
|
assertTrue(res.isUnknown());
|
2022-04-28 17:47:10 -07:00
|
|
|
UnknownExplanation ue = res.getUnknownExplanation();
|
2024-09-17 11:13:04 -05:00
|
|
|
assertEquals(ue, UnknownExplanation.INCOMPLETE);
|
|
|
|
|
assertEquals(ue.toString(), "INCOMPLETE");
|
2021-05-13 20:15:21 -05:00
|
|
|
}
|
|
|
|
|
}
|