use of org.sosy_lab.java_smt.api.StringFormula in project java-smt by sosy-lab.
the class ArrayFormulaManagerTest method testStringIndexStringValue.
/*
* Test whether or not String Arrays are possible with String indexes
*/
@Test
public void testStringIndexStringValue() throws SolverException, InterruptedException {
requireStrings();
// (arr2 = store(arr1, "four", "two")) & !(select(arr2, "four") = "two")
StringFormula num2 = smgr.makeString("two");
StringFormula num4 = smgr.makeString("four");
ArrayFormula<StringFormula, StringFormula> arr1 = amgr.makeArray("arr1", StringType, StringType);
ArrayFormula<StringFormula, StringFormula> arr2 = amgr.makeArray("arr2", StringType, StringType);
BooleanFormula query = bmgr.and(amgr.equivalence(arr2, amgr.store(arr1, num4, num2)), bmgr.not(smgr.equal(num2, amgr.select(arr2, num4))));
assertThatFormula(query).isUnsatisfiable();
}
use of org.sosy_lab.java_smt.api.StringFormula in project java-smt by sosy-lab.
the class StringFormulaManagerTest method testConstStringReplace.
@Test
public void testConstStringReplace() throws SolverException, InterruptedException {
for (int i = 0; i < WORDS.size(); i++) {
for (int j = 2; j < WORDS.size(); j++) {
String word1 = WORDS.get(j - 1);
String word2 = WORDS.get(j);
String word3 = WORDS.get(i);
StringFormula word1F = smgr.makeString(word1);
StringFormula word2F = smgr.makeString(word2);
StringFormula word3F = smgr.makeString(word3);
StringFormula result = smgr.makeString(word3.replaceFirst(word2, word1));
assertEqual(smgr.replace(word3F, word2F, word1F), result);
}
}
}
use of org.sosy_lab.java_smt.api.StringFormula in project java-smt by sosy-lab.
the class StringFormulaManagerTest method testStringLengthInequalityPositiveRange.
/**
* Test String formulas with inequalities in the negative range.
*
* <p>0 < stringVariable length < 1 -> UNSAT
*
* <p>0 < stringVariable length < 2 -> SAT
*
* <p>0 <= stringVariable length < 1 -> SAT implies stringVariable = ""
*
* <p>1 < stringVariable length < 3 -> SAT implies stringVariable length = 2
*/
@Test
public void testStringLengthInequalityPositiveRange() throws SolverException, InterruptedException {
StringFormula stringVariable = smgr.makeVariable("stringVariable");
IntegerFormula stringVariableLength = smgr.length(stringVariable);
IntegerFormula three = imgr.makeNumber(3);
IntegerFormula two = imgr.makeNumber(2);
IntegerFormula one = imgr.makeNumber(1);
IntegerFormula zero = imgr.makeNumber(0);
// 0 < stringVariable length < 1 -> UNSAT
assertThatFormula(bmgr.and(imgr.lessThan(zero, stringVariableLength), imgr.lessThan(stringVariableLength, one))).isUnsatisfiable();
// 0 < stringVariable length < 2 -> SAT
assertThatFormula(bmgr.and(imgr.lessThan(zero, stringVariableLength), imgr.lessThan(stringVariableLength, two))).isSatisfiable();
// 0 <= stringVariable length < 1 -> SAT implies stringVariable = ""
assertThatFormula(bmgr.and(imgr.lessOrEquals(zero, stringVariableLength), imgr.lessThan(stringVariableLength, one))).implies(smgr.equal(stringVariable, smgr.makeString("")));
// 1 < stringVariable length < 3 -> SAT implies stringVariable length = 2
assertThatFormula(bmgr.and(imgr.lessThan(one, stringVariableLength), imgr.lessThan(stringVariableLength, three))).implies(imgr.equal(smgr.length(stringVariable), two));
}
use of org.sosy_lab.java_smt.api.StringFormula in project java-smt by sosy-lab.
the class StringFormulaManagerTest method testStringConcatEmpty.
@Test
public void testStringConcatEmpty() throws SolverException, InterruptedException {
StringFormula empty = smgr.makeString("");
assertEqual(empty, smgr.concat(ImmutableList.of()));
assertEqual(empty, smgr.concat(empty));
assertEqual(empty, smgr.concat(empty, empty));
assertEqual(empty, smgr.concat(ImmutableList.of(empty, empty, empty, empty)));
}
use of org.sosy_lab.java_smt.api.StringFormula in project java-smt by sosy-lab.
the class StringFormulaManagerTest method testSimpleStringVariableLexicographicOrdering.
/**
* Test simple String lexicographic ordering (< <= > >=) for String variables.
*/
@Test
public void testSimpleStringVariableLexicographicOrdering() throws SolverException, InterruptedException {
StringFormula a = smgr.makeString("a");
StringFormula b = smgr.makeString("b");
StringFormula ab = smgr.makeString("ab");
StringFormula abc = smgr.makeString("abc");
StringFormula abd = smgr.makeString("abd");
StringFormula abe = smgr.makeString("abe");
StringFormula abaab = smgr.makeString("abaab");
StringFormula abbab = smgr.makeString("abbab");
StringFormula abcab = smgr.makeString("abcab");
StringFormula stringVariable = smgr.makeVariable("stringVariable");
assertThatFormula(bmgr.and(smgr.lessThan(a, stringVariable), smgr.lessThan(stringVariable, b), imgr.equal(imgr.makeNumber(0), smgr.length(stringVariable)))).implies(smgr.equal(stringVariable, smgr.makeString("")));
assertThatFormula(bmgr.and(smgr.lessOrEquals(a, stringVariable), smgr.lessThan(stringVariable, b), imgr.equal(imgr.makeNumber(1), smgr.length(stringVariable)))).implies(smgr.equal(stringVariable, smgr.makeString("a")));
assertThatFormula(bmgr.and(smgr.lessThan(a, stringVariable), smgr.lessOrEquals(stringVariable, b), imgr.equal(imgr.makeNumber(1), smgr.length(stringVariable)))).implies(smgr.equal(stringVariable, b));
assertThatFormula(bmgr.and(smgr.lessOrEquals(abc, stringVariable), smgr.lessThan(stringVariable, abd), imgr.equal(imgr.makeNumber(3), smgr.length(stringVariable)))).implies(smgr.equal(stringVariable, abc));
assertThatFormula(bmgr.and(smgr.lessThan(abc, stringVariable), smgr.lessThan(stringVariable, abe), imgr.equal(imgr.makeNumber(3), smgr.length(stringVariable)))).implies(smgr.equal(stringVariable, abd));
assertThatFormula(bmgr.and(smgr.lessThan(abc, stringVariable), smgr.lessOrEquals(stringVariable, abd), imgr.equal(imgr.makeNumber(3), smgr.length(stringVariable)))).implies(smgr.equal(stringVariable, abd));
assertThatFormula(bmgr.and(smgr.lessThan(abaab, stringVariable), smgr.lessThan(stringVariable, abcab), smgr.prefix(ab, stringVariable), smgr.suffix(ab, stringVariable), imgr.equal(imgr.makeNumber(5), smgr.length(stringVariable)))).implies(smgr.equal(stringVariable, abbab));
}
Aggregations