Search in sources :

Example 1 with StringFormula

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();
}
Also used : StringFormula(org.sosy_lab.java_smt.api.StringFormula) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Test(org.junit.Test)

Example 2 with StringFormula

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);
        }
    }
}
Also used : StringFormula(org.sosy_lab.java_smt.api.StringFormula) Test(org.junit.Test)

Example 3 with StringFormula

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));
}
Also used : IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) StringFormula(org.sosy_lab.java_smt.api.StringFormula) Test(org.junit.Test)

Example 4 with StringFormula

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)));
}
Also used : StringFormula(org.sosy_lab.java_smt.api.StringFormula) Test(org.junit.Test)

Example 5 with StringFormula

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));
}
Also used : StringFormula(org.sosy_lab.java_smt.api.StringFormula) Test(org.junit.Test)

Aggregations

StringFormula (org.sosy_lab.java_smt.api.StringFormula)48 Test (org.junit.Test)47 IntegerFormula (org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula)15 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)12 BooleanFormulaTransformationVisitor (org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor)3 FormulaTransformationVisitor (org.sosy_lab.java_smt.api.visitors.FormulaTransformationVisitor)3 BitvectorFormula (org.sosy_lab.java_smt.api.BitvectorFormula)2 ImmutableList (com.google.common.collect.ImmutableList)1 CheckReturnValue (com.google.errorprone.annotations.CheckReturnValue)1 Ignore (org.junit.Ignore)1 ArrayFormula (org.sosy_lab.java_smt.api.ArrayFormula)1 FloatingPointFormula (org.sosy_lab.java_smt.api.FloatingPointFormula)1 FloatingPointFormulaManager (org.sosy_lab.java_smt.api.FloatingPointFormulaManager)1 NumeralFormula (org.sosy_lab.java_smt.api.NumeralFormula)1 RegexFormula (org.sosy_lab.java_smt.api.RegexFormula)1