2023-10-12 12:05:01 -05:00
|
|
|
/******************************************************************************
|
|
|
|
|
* Top contributors (to current version):
|
2025-01-23 09:54:20 -08:00
|
|
|
* Abdalrhman Mohamed, Hans-Joerg Schurr, Aina Niemetz
|
2023-10-12 12:05:01 -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
|
2023-10-12 12:05:01 -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 guards of the Java API functions.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package tests;
|
|
|
|
|
import static io.github.cvc5.Kind.*;
|
|
|
|
|
import static io.github.cvc5.SortKind.*;
|
|
|
|
|
import static io.github.cvc5.ProofRule.*;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
|
|
|
|
|
|
import io.github.cvc5.*;
|
|
|
|
|
import java.math.BigInteger;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
class ProofTest
|
|
|
|
|
{
|
2024-04-02 09:42:06 -07:00
|
|
|
private TermManager d_tm;
|
2023-10-12 12:05:01 -05:00
|
|
|
private Solver d_solver;
|
|
|
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
|
void setUp()
|
|
|
|
|
{
|
2024-04-02 09:42:06 -07:00
|
|
|
d_tm = new TermManager();
|
|
|
|
|
d_solver = new Solver(d_tm);
|
2023-10-12 12:05:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AfterEach
|
|
|
|
|
void tearDown()
|
|
|
|
|
{
|
|
|
|
|
Context.deletePointers();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-06 16:18:28 -07:00
|
|
|
Proof createProof() throws CVC5ApiException
|
2023-10-12 12:05:01 -05:00
|
|
|
{
|
|
|
|
|
d_solver.setOption("produce-proofs", "true");
|
|
|
|
|
|
2024-04-02 09:42:06 -07:00
|
|
|
Sort uSort = d_tm.mkUninterpretedSort("u");
|
|
|
|
|
Sort intSort = d_tm.getIntegerSort();
|
|
|
|
|
Sort boolSort = d_tm.getBooleanSort();
|
|
|
|
|
Sort uToIntSort = d_tm.mkFunctionSort(uSort, intSort);
|
|
|
|
|
Sort intPredSort = d_tm.mkFunctionSort(intSort, boolSort);
|
2023-10-12 12:05:01 -05:00
|
|
|
|
2024-04-02 09:42:06 -07:00
|
|
|
Term x = d_tm.mkConst(uSort, "x");
|
|
|
|
|
Term y = d_tm.mkConst(uSort, "y");
|
|
|
|
|
Term f = d_tm.mkConst(uToIntSort, "f");
|
|
|
|
|
Term p = d_tm.mkConst(intPredSort, "p");
|
|
|
|
|
Term zero = d_tm.mkInteger(0);
|
|
|
|
|
Term one = d_tm.mkInteger(1);
|
|
|
|
|
Term f_x = d_tm.mkTerm(Kind.APPLY_UF, f, x);
|
|
|
|
|
Term f_y = d_tm.mkTerm(Kind.APPLY_UF, f, y);
|
|
|
|
|
Term sum = d_tm.mkTerm(Kind.ADD, f_x, f_y);
|
|
|
|
|
Term p_0 = d_tm.mkTerm(Kind.APPLY_UF, p, zero);
|
|
|
|
|
Term p_f_y = d_tm.mkTerm(APPLY_UF, p, f_y);
|
|
|
|
|
d_solver.assertFormula(d_tm.mkTerm(Kind.GT, zero, f_x));
|
|
|
|
|
d_solver.assertFormula(d_tm.mkTerm(Kind.GT, zero, f_y));
|
|
|
|
|
d_solver.assertFormula(d_tm.mkTerm(Kind.GT, sum, one));
|
2023-10-12 12:05:01 -05:00
|
|
|
d_solver.assertFormula(p_0);
|
|
|
|
|
d_solver.assertFormula(p_f_y.notTerm());
|
|
|
|
|
assertTrue(d_solver.checkSat().isUnsat());
|
|
|
|
|
|
|
|
|
|
return d_solver.getProof()[0];
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-18 08:09:59 -07:00
|
|
|
Proof createRewriteProof() throws CVC5ApiException
|
|
|
|
|
{
|
|
|
|
|
d_solver.setOption("produce-proofs", "true");
|
|
|
|
|
d_solver.setOption("proof-granularity", "dsl-rewrite");
|
|
|
|
|
Sort intSort = d_tm.getIntegerSort();
|
|
|
|
|
Term x = d_tm.mkConst(intSort, "x");
|
2025-02-10 16:35:29 -06:00
|
|
|
Term zero = d_tm.mkInteger(0);
|
|
|
|
|
Term geq = d_tm.mkTerm(Kind.GEQ, new Term[]{x, zero});
|
|
|
|
|
Term leq = d_tm.mkTerm(Kind.LEQ, new Term[]{zero, x});
|
2024-04-18 08:09:59 -07:00
|
|
|
d_solver.assertFormula(
|
2025-02-10 16:35:29 -06:00
|
|
|
d_tm.mkTerm(Kind.DISTINCT, new Term[]{geq, leq}));
|
2024-04-18 08:09:59 -07:00
|
|
|
d_solver.checkSat();
|
|
|
|
|
return d_solver.getProof()[0];
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-06 16:18:28 -07:00
|
|
|
@Test
|
|
|
|
|
void nullProof() throws CVC5ApiException
|
|
|
|
|
{
|
|
|
|
|
Proof proof = new Proof();
|
|
|
|
|
assertEquals(proof.getRule(), ProofRule.UNKNOWN);
|
|
|
|
|
assertEquals(ProofRule.UNKNOWN.hashCode(), ProofRule.UNKNOWN.hashCode());
|
|
|
|
|
assertTrue(proof.getResult().isNull());
|
|
|
|
|
assertTrue(proof.getChildren().length == 0);
|
|
|
|
|
assertTrue(proof.getArguments().length == 0);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-24 16:19:01 -07:00
|
|
|
@Test
|
|
|
|
|
void equalHash() throws CVC5ApiException
|
|
|
|
|
{
|
|
|
|
|
Proof x = createProof();
|
|
|
|
|
Proof y = x.getChildren()[0];
|
|
|
|
|
Proof n = new Proof();
|
|
|
|
|
assertTrue(x.equals(x));
|
|
|
|
|
assertFalse(x.equals(y));
|
|
|
|
|
assertFalse(x.equals(n));
|
|
|
|
|
|
|
|
|
|
assertTrue(x.hashCode() == x.hashCode());
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-12 12:05:01 -05:00
|
|
|
@Test
|
|
|
|
|
void getRule() throws CVC5ApiException
|
|
|
|
|
{
|
2024-06-06 16:18:28 -07:00
|
|
|
Proof proof = createProof();
|
2023-10-12 12:05:01 -05:00
|
|
|
assertEquals(ProofRule.SCOPE, proof.getRule());
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-18 08:09:59 -07:00
|
|
|
@Test
|
|
|
|
|
void getRewriteRule() throws CVC5ApiException
|
|
|
|
|
{
|
|
|
|
|
Proof proof = createRewriteProof();
|
|
|
|
|
assertThrows(CVC5ApiException.class, () -> proof.getRewriteRule());
|
|
|
|
|
ProofRule rule;
|
|
|
|
|
List<Proof> stack = new ArrayList<Proof>();
|
|
|
|
|
stack.add(proof);
|
|
|
|
|
Proof curr;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
curr = stack.get(stack.size() - 1);
|
|
|
|
|
stack.remove(stack.size() - 1);
|
|
|
|
|
rule = curr.getRule();
|
|
|
|
|
Proof[] children = curr.getChildren();
|
|
|
|
|
stack.addAll(Arrays.asList(children));
|
|
|
|
|
} while (rule != ProofRule.DSL_REWRITE);
|
|
|
|
|
Proof rewriteProof = curr;
|
|
|
|
|
assertDoesNotThrow(() -> rewriteProof.getRewriteRule());
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-12 12:05:01 -05:00
|
|
|
@Test
|
|
|
|
|
void getResult() throws CVC5ApiException
|
|
|
|
|
{
|
2024-06-06 16:18:28 -07:00
|
|
|
Proof proof = createProof();
|
2023-10-12 12:05:01 -05:00
|
|
|
assertDoesNotThrow(() -> proof.getResult());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getChildren() throws CVC5ApiException
|
|
|
|
|
{
|
2024-06-06 16:18:28 -07:00
|
|
|
Proof proof = createProof();
|
2023-10-12 12:05:01 -05:00
|
|
|
Proof[] children = proof.getChildren();
|
|
|
|
|
assertNotEquals(0, children.length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void getArguments() throws CVC5ApiException
|
|
|
|
|
{
|
2024-06-06 16:18:28 -07:00
|
|
|
Proof proof = createProof();
|
2023-10-12 12:05:01 -05:00
|
|
|
assertDoesNotThrow(() -> proof.getArguments());
|
|
|
|
|
}
|
2024-07-10 10:57:05 -07:00
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void eq() throws CVC5ApiException
|
|
|
|
|
{
|
|
|
|
|
Proof x = createProof();
|
|
|
|
|
Proof y = x.getChildren()[0];
|
|
|
|
|
Proof z = new Proof();
|
|
|
|
|
|
|
|
|
|
assertTrue(x.equals(x));
|
|
|
|
|
assertFalse(x.equals(y));
|
|
|
|
|
assertFalse(x.equals(z));
|
|
|
|
|
|
|
|
|
|
assertTrue(x.hashCode() == x.hashCode());
|
|
|
|
|
}
|
2023-10-12 12:05:01 -05:00
|
|
|
}
|