Skip to content

Commit 7ebcdbf

Browse files
Visitor: Add tests integer-bitvector conversion and division in the visitor
1 parent 58fa61b commit 7ebcdbf

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/org/sosy_lab/java_smt/test/SolverVisitorTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,57 @@ public void rationalConstantVisit() {
310310
}
311311
}
312312

313+
@Test
314+
public void integerDivisionVisit() {
315+
requireIntegers();
316+
assume().that(solver).isNotEqualTo(Solvers.PRINCESS); // Princess will rewrite the term
317+
318+
IntegerFormula x = imgr.makeVariable("x");
319+
IntegerFormula y = imgr.makeVariable("y");
320+
IntegerFormula c = imgr.makeNumber(7);
321+
322+
if (solver.equals(Solvers.MATHSAT5)) {
323+
// MathSAT will rewrite if we don't use a variable in the denominator
324+
checkKind(imgr.divide(x, y), FunctionDeclarationKind.DIV);
325+
} else {
326+
// Otherwise, just use a constant to support solvers that don't have non-linear arithmetics
327+
checkKind(imgr.divide(x, c), FunctionDeclarationKind.DIV);
328+
}
329+
}
330+
331+
@Test
332+
public void integerToBitvectorConversionVisit() {
333+
requireIntegers();
334+
requireBitvectors();
335+
336+
// Yices does not support integer to bitvector conversions
337+
assume().that(solver).isNotEqualTo(Solvers.YICES2);
338+
// Princess uses mod_casts internally, which makes it hard to figure out when conversion happen
339+
// TODO Find out if mod_cast/int_cast could be mapped to (S)BV_TO_INT and INT_TO_BV
340+
assume().that(solver).isNotEqualTo(Solvers.PRINCESS);
341+
342+
IntegerFormula x = imgr.makeVariable("x");
343+
checkKind(bvmgr.makeBitvector(8, x), FunctionDeclarationKind.INT_TO_BV);
344+
}
345+
346+
@Test
347+
public void bitvectorToIntegerConversionVisit() {
348+
requireIntegers();
349+
requireBitvectors();
350+
351+
// Yices does not support integer to bitvector conversions
352+
assume().that(solver).isNotEqualTo(Solvers.YICES2);
353+
// CVC4, CVC5 and Z3 will rewrite SBV_TO_INT to a term that only uses unsigned integers
354+
assume().that(solver).isNoneOf(Solvers.Z3, Solvers.CVC4, Solvers.CVC5);
355+
// Princess uses mod_casts internally, which makes it hard to figure out when conversion happen
356+
assume().that(solver).isNotEqualTo(Solvers.PRINCESS);
357+
358+
BitvectorFormula y = bvmgr.makeVariable(8, "y");
359+
360+
checkKind(bvmgr.toIntegerFormula(y, true), FunctionDeclarationKind.SBV_TO_INT);
361+
checkKind(bvmgr.toIntegerFormula(y, false), FunctionDeclarationKind.UBV_TO_INT);
362+
}
363+
313364
@Test
314365
public void arrayVisit() {
315366
requireArrays();

0 commit comments

Comments
 (0)