Skip to content

Commit 08c5594

Browse files
author
BaierD
committed
Add native test for Mathsat5 proof API
1 parent 1d05d3b commit 08c5594

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

src/org/sosy_lab/java_smt/solvers/mathsat5/Mathsat5NativeApiTest.java

+58
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_decl_get_name;
1818
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_destroy_config;
1919
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_destroy_model_iterator;
20+
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_destroy_proof_manager;
2021
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_from_smtlib2;
2122
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_get_enum_constants;
2223
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_get_enum_type;
2324
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_get_integer_type;
2425
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_get_model;
2526
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_get_model_value;
27+
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_get_proof;
28+
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_get_proof_manager;
2629
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_get_rational_type;
2730
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_is_enum_type;
2831
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_is_integer_type;
@@ -43,6 +46,11 @@
4346
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_model_iterator_has_next;
4447
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_model_iterator_next;
4548
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_pop_backtrack_point;
49+
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_proof_get_arity;
50+
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_proof_get_child;
51+
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_proof_get_name;
52+
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_proof_id;
53+
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_proof_is_term;
4654
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_push_backtrack_point;
4755
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_set_option_checked;
4856
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_term_get_type;
@@ -90,6 +98,56 @@ public void createEnvironment() {
9098
var = msat_make_variable(env, "rat", rationalType);
9199
}
92100

101+
@Test
102+
public void proofTest() throws IllegalStateException, InterruptedException, SolverException {
103+
long cfg = msat_create_config();
104+
105+
msat_set_option_checked(cfg, "proof_generation", "true");
106+
107+
env = msat_create_env(cfg);
108+
msat_destroy_config(cfg);
109+
110+
const0 = msat_make_number(env, "0");
111+
const1 = msat_make_number(env, "1");
112+
long rationalType = msat_get_rational_type(env);
113+
var = msat_make_variable(env, "rat", rationalType);
114+
115+
msat_push_backtrack_point(env);
116+
117+
msat_assert_formula(env, msat_make_equal(env, var, const0));
118+
msat_assert_formula(env, msat_make_equal(env, var, const1));
119+
120+
// UNSAT
121+
assertThat(msat_check_sat(env)).isFalse();
122+
123+
long proofMgr = msat_get_proof_manager(env);
124+
long proof = msat_get_proof(proofMgr);
125+
126+
assertThat(msat_proof_is_term(proof)).isFalse();
127+
128+
assertThat(msat_proof_get_arity(proof)).isEqualTo(1);
129+
130+
String proofName = msat_proof_get_name(proof);
131+
assertThat(proofName).isEqualTo("res-chain");
132+
133+
// Child is also a proof
134+
long proofChild = msat_proof_get_child(proof, 0);
135+
assertThat(msat_proof_get_name(proofChild)).isEqualTo("clause-hyp");
136+
assertThat(msat_proof_is_term(proofChild)).isFalse();
137+
assertThat(msat_proof_get_arity(proofChild)).isEqualTo(0);
138+
139+
// Can be used to check for the equality of proofs
140+
int proofID = msat_proof_id(proof);
141+
int proofChildID = msat_proof_id(proofChild);
142+
assertThat(proofChildID).isNotEqualTo(proofID);
143+
144+
// TODO: test term representation of a proof
145+
// long term = msat_proof_get_term(proofChild2);
146+
147+
// Cleans up the proof manager and the associated proof
148+
msat_destroy_proof_manager(proofMgr);
149+
}
150+
93151
/** x == 0 and sin(x) == 0 SAT; x == 1 and sin(x) == 0 UNSAT. */
94152
@Test
95153
public void sinTest() throws IllegalStateException, InterruptedException, SolverException {

0 commit comments

Comments
 (0)