Search in sources :

Example 21 with TheoryTestingSupport

use of com.sri.ai.grinder.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.

the class AbstractEqualityConstraintTest method testCompleteSatisfiabilitySpecialCases.

@Test
public void testCompleteSatisfiabilitySpecialCases() {
    // This test is to make sure that some more tricky cases are indeed tested,
    // even though hopefully the large amount of generated random problems include them or their variants.
    String conjunction;
    Expression expected;
    TheoryTestingSupport theoryTestingSupport = makeTheoryTestingSupport();
    Map<String, Type> variableNamesAndTypes = new HashMap<>(theoryTestingSupport.getVariableNamesAndTypesForTesting());
    variableNamesAndTypes.put("W", variableNamesAndTypes.get("X"));
    theoryTestingSupport.setVariableNamesAndTypesForTesting(variableNamesAndTypes);
    if (theoryTestingSupport.getTheory().singleVariableConstraintIsCompleteWithRespectToItsVariable()) {
        conjunction = "X != a and X != b and X != sometype5 and X != Z and X != W and Z = c and W = d";
        expected = null;
        runCompleteSatisfiabilityTest(conjunction, expected, theoryTestingSupport);
        conjunction = "X = Y and X != a and X != b and X != sometype5 and X != Z and X != W and Z = c and W = d";
        expected = null;
        runCompleteSatisfiabilityTest(conjunction, expected, theoryTestingSupport);
    }
    TheoryTestingSupport theoryTestingSupport2 = makeTheoryTestingSupport();
    Categorical type = new Categorical("Type", 1, arrayList(parse("a")));
    theoryTestingSupport2.setVariableNamesAndTypesForTesting(map("X", type, "Y", type, "Z", type, "W", type));
    conjunction = "X != Y";
    expected = null;
    runCompleteSatisfiabilityTest(conjunction, expected, theoryTestingSupport2);
    TheoryTestingSupport theoryTestingSupport3 = makeTheoryTestingSupport();
    type = new Categorical("Type", 2, arrayList(parse("a"), parse("b")));
    theoryTestingSupport3.setVariableNamesAndTypesForTesting(map("X", type, "Y", type, "Z", type, "W", type));
    conjunction = "X != Y and X != a";
    expected = parse("Y != b and X != a and X != Y");
    runCompleteSatisfiabilityTest(conjunction, expected, theoryTestingSupport3);
    conjunction = "X != a and X != b and X != c and X != sometype5 and X != Y";
    expected = parse("Y != d and X != a and X != b and X != c and X != sometype5 and X != Y and X != Y");
    runCompleteSatisfiabilityTest(conjunction, expected, theoryTestingSupport);
    conjunction = "X = a and X != b and X != sometype5 and X != Z and X != W and Z = c and W = d";
    expected = parse("(W = d) and (Z = c) and (X = a) and (X != Z) and (X != W)");
    runCompleteSatisfiabilityTest(conjunction, expected, theoryTestingSupport);
}
Also used : Type(com.sri.ai.expresso.api.Type) Expression(com.sri.ai.expresso.api.Expression) HashMap(java.util.HashMap) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) Categorical(com.sri.ai.expresso.type.Categorical) AbstractTheoryIncludingEqualityTest(com.sri.ai.test.grinder.theory.base.AbstractTheoryIncludingEqualityTest) Test(org.junit.Test)

Example 22 with TheoryTestingSupport

use of com.sri.ai.grinder.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.

the class LinearRealArithmeticTheoryTest method testMeasure.

@Test
public void testMeasure() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new LinearRealArithmeticTheory(true, true));
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    Expression variable;
    String constraintString;
    Expression expected;
    variable = parse("X");
    constraintString = "true";
    expected = parse("4");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < 3";
    expected = parse("3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X <= 3";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X < 4";
    expected = parse("1");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4 and X != 3.2";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2 and X = 3.2";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.2";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < Y";
    expected = parse("if Y > 0 then Y else 0");
    runMeasureTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X < Y + 1";
    expected = parse("if Y > 3 then 4 else Y + 1");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < Y - 4";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < 2 - Y";
    expected = parse("if Y < 2 then -Y + 2 else 0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > Y";
    expected = parse("if Y < 4 then 4 - Y else 0");
    runMeasureTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X > Y + 1";
    expected = parse("if Y < 3 then 4 - (Y + 1) else 0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y + 4";
    expected = parse("if Y <= 0 then 4 - (Y + 4) else 0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y + 2";
    expected = parse("if Y <= 2 then 4 - (Y + 2) else 0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y";
    expected = parse("4 - Y");
    runMeasureTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X >= Y + 1";
    expected = parse("if Y <= 3 then 4 - (Y + 1) else 0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X <= 3";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4 and X != 3.2";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2 and X = 3.2";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.2";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.6";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > Z and X >= Y";
    expected = parse("if Z < Y then if Y <= 3.4 then 3.4 - Y else 0 else if Z < 3.4 then 3.4 - Z else 0");
    runMeasureTest(variable, constraintString, expected, context);
}
Also used : Context(com.sri.ai.grinder.api.Context) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) Test(org.junit.Test)

Example 23 with TheoryTestingSupport

use of com.sri.ai.grinder.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.

the class LinearRealArithmeticTheoryTest method testMeasureEquivalentInterval.

@Test
public void testMeasureEquivalentInterval() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new LinearRealArithmeticTheory(true, true));
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    Expression variable;
    String constraintString;
    Expression expected;
    variable = parse("X");
    constraintString = "true";
    expected = parse("[0;4]");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < 3";
    expected = parse("[0;3[");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X <= 3";
    expected = parse("{}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4";
    expected = parse("]3.1; 3.4]");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X < 4";
    expected = parse("]3; 4[");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4 and X != 3.2";
    expected = parse("]3.1; 3.4]");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2";
    expected = parse("]3.1; 3.4]");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2 and X = 3.2";
    expected = parse("{}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.2";
    expected = parse("{ 3.2 }");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7";
    expected = parse("]3.1; 3.4]");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7";
    expected = parse("{}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7";
    expected = parse("{}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 8";
    expected = parse("{}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7 and X = 8";
    expected = parse("{}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7 and X = 8";
    expected = parse("{}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < Y";
    expected = parse("if Y > 0 then [0;Y[ else {}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X < Y + 1";
    // see previous test for situation in which condition is always true
    expected = parse("if Y > 3 then [0;4] else [0 ; Y + 1[");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X <= 3";
    expected = parse("{}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4";
    expected = parse("]3.1; 3.4]");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4 and X != 3.2";
    expected = parse("]3.1; 3.4]");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2";
    expected = parse("]3.1; 3.4]");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2 and X = 3.2";
    expected = parse("{}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.2";
    expected = parse("{ 3.2 }");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.6";
    expected = parse("{}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7";
    expected = parse("]3.1; 3.4]");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7";
    expected = parse("{}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7";
    expected = parse("{}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 8";
    expected = parse("{}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7 and X = 8";
    expected = parse("{}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7 and X = 8";
    expected = parse("{}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > Z and X >= Y";
    expected = parse("if Z < Y then if Y <= 3.4 then [Y;3.4] else {} else if Z < 3.4 then ]Z;3.4] else {}");
    runMeasureEquivalentIntervalTest(variable, constraintString, expected, context);
}
Also used : Context(com.sri.ai.grinder.api.Context) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) Test(org.junit.Test)

Example 24 with TheoryTestingSupport

use of com.sri.ai.grinder.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.

the class LinearRealArithmeticTheoryTest method testSummation.

@Test
public void testSummation() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new LinearRealArithmeticTheory(true, true));
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    Simplifier simplifier = (e, c) -> theoryTestingSupport.getTheory().simplify(e, c);
    Expression variable;
    String constraintString;
    String bodyString;
    Expression expected;
    variable = parse("X");
    constraintString = "true";
    bodyString = "1";
    expected = parse("4");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
    variable = parse("X");
    constraintString = "X < 3 and X != 2";
    bodyString = "1";
    expected = parse("3");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
    variable = parse("X");
    constraintString = "X < Y and X != 2";
    bodyString = "1";
    expected = parse("if Y > 0 then Y else 0");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
    variable = parse("X");
    constraintString = "X < 3 and X != 2";
    bodyString = "Y";
    expected = parse("3*Y");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
    variable = parse("X");
    constraintString = "X < 3 and X != 2";
    bodyString = "X";
    expected = parse("4.5");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
    variable = parse("X");
    constraintString = "X < 3 and X != 2 and X = 2";
    bodyString = "Y";
    expected = parse("0");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
    variable = parse("X");
    constraintString = "X < Y and X != 2";
    bodyString = "X";
    expected = parse("if Y > 0 then 0.5*Y^2 else 0");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
    variable = parse("X");
    constraintString = "X < Y and X != 2";
    bodyString = "Y";
    expected = parse("if Y > 0 then Y^2 else 0");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
    variable = parse("X");
    constraintString = "X < Y and X != 2";
    bodyString = "X + Y";
    expected = parse("if Y > 0 then 1.5*Y^2 else 0");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
// variable = parse("X");
// constraintString = "X < Y and X != 2";
// bodyString = "X^2 + Y";
// expected = parse("if Y > 0 then 0.333333333*Y^3 + Y^2 else 0");
// runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
}
Also used : Context(com.sri.ai.grinder.api.Context) BinaryFunction(com.sri.ai.util.base.BinaryFunction) Function(com.google.common.base.Function) DefaultSingleQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem) SatisfiabilityOfSingleVariableLinearRealArithmeticConstraintStepSolver(com.sri.ai.grinder.theory.linearrealarithmetic.SatisfiabilityOfSingleVariableLinearRealArithmeticConstraintStepSolver) SingleVariableLinearRealArithmeticConstraint(com.sri.ai.grinder.theory.linearrealarithmetic.SingleVariableLinearRealArithmeticConstraint) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) Random(java.util.Random) Test(org.junit.Test) Expression(com.sri.ai.expresso.api.Expression) Beta(com.google.common.annotations.Beta) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) SummationOnLinearRealArithmeticAndPolynomialStepSolver(com.sri.ai.grinder.theory.linearrealarithmetic.SummationOnLinearRealArithmeticAndPolynomialStepSolver) Expressions.parse(com.sri.ai.expresso.helper.Expressions.parse) ExpressionStepSolver(com.sri.ai.grinder.api.ExpressionStepSolver) Sum(com.sri.ai.grinder.group.Sum) SingleVariableConstraint(com.sri.ai.grinder.api.SingleVariableConstraint) Simplifier(com.sri.ai.grinder.rewriter.api.Simplifier) Context(com.sri.ai.grinder.api.Context) IntervalWithMeasureEquivalentToSingleVariableLinearRealArithmeticConstraintStepSolver(com.sri.ai.grinder.theory.linearrealarithmetic.IntervalWithMeasureEquivalentToSingleVariableLinearRealArithmeticConstraintStepSolver) Assert.assertEquals(org.junit.Assert.assertEquals) MeasureOfSingleVariableLinearRealArithmeticConstraintStepSolver(com.sri.ai.grinder.theory.linearrealarithmetic.MeasureOfSingleVariableLinearRealArithmeticConstraintStepSolver) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) Simplifier(com.sri.ai.grinder.rewriter.api.Simplifier) Test(org.junit.Test)

Example 25 with TheoryTestingSupport

use of com.sri.ai.grinder.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.

the class LinearRealArithmeticTheoryTest method testSatisfiability.

@Test
public void testSatisfiability() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new LinearRealArithmeticTheory(true, true));
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    Expression variable;
    String constraintString;
    Expression expected;
    variable = parse("X");
    constraintString = "true";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < 3";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X <= 3";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X < 4";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4 and X != 3.2";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2 and X = 3.2";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.2";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 8";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7 and X = 8";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7 and X = 8";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < Y";
    expected = parse("Y > 0");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X < Y + 1";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < Y - 4";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < 2 - Y";
    expected = parse("Y < 2");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > Y";
    expected = parse("Y < 4");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X > Y + 1";
    expected = parse("Y < 3");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y + 4";
    expected = parse("Y <= 0");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y + 2";
    expected = parse("Y <= 2");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X >= Y + 1";
    expected = parse("Y <= 3");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X <= 3";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4 and X != 3.2";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2 and X = 3.2";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.2";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.6";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 8";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7 and X = 8";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7 and X = 8";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > Z and X >= Y";
    expected = parse("if Z < Y then Y <= 3.4 else Z < 3.4");
    runSatisfiabilityTest(variable, constraintString, expected, context);
}
Also used : Context(com.sri.ai.grinder.api.Context) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) Test(org.junit.Test)

Aggregations

TheoryTestingSupport (com.sri.ai.grinder.tester.TheoryTestingSupport)49 Test (org.junit.Test)42 Context (com.sri.ai.grinder.api.Context)36 Expression (com.sri.ai.expresso.api.Expression)26 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)22 EqualityTheory (com.sri.ai.grinder.theory.equality.EqualityTheory)20 PropositionalTheory (com.sri.ai.grinder.theory.propositional.PropositionalTheory)17 FunctionType (com.sri.ai.expresso.type.FunctionType)13 Type (com.sri.ai.expresso.api.Type)12 CompoundTheory (com.sri.ai.grinder.theory.compound.CompoundTheory)11 StepSolver (com.sri.ai.grinder.api.StepSolver)10 UnificationStepSolver (com.sri.ai.grinder.theory.base.UnificationStepSolver)10 AbstractTheoryTestingSupport (com.sri.ai.grinder.core.constraint.AbstractTheoryTestingSupport)9 LinearRealArithmeticTheory (com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory)9 LinkedHashMap (java.util.LinkedHashMap)7 Constraint (com.sri.ai.grinder.api.Constraint)6 CompleteMultiVariableContext (com.sri.ai.grinder.core.constraint.CompleteMultiVariableContext)6 Ignore (org.junit.Ignore)5 Categorical (com.sri.ai.expresso.type.Categorical)4 TrueContext (com.sri.ai.grinder.core.TrueContext)4