use of com.sri.ai.grinder.sgdpllt.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);
}
use of com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.
the class MaximumExpressionStepSolverTest method test.
@Test
public void test() {
TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new DifferenceArithmeticTheory(true, true));
Context context = theoryTestingSupport.makeContextWithTestingInformation();
List<String> expressionStrings;
String order;
Expression orderMinimum;
Expression orderMaximum;
Expression expected;
expressionStrings = list("I", "J");
expected = parse("if I < J then J else I");
order = LESS_THAN;
orderMinimum = MINUS_INFINITY;
orderMaximum = INFINITY;
runTest(expressionStrings, order, orderMinimum, orderMaximum, expected, context);
expressionStrings = list("I", "J");
expected = parse("if I > J then J else I");
order = GREATER_THAN;
orderMinimum = INFINITY;
orderMaximum = MINUS_INFINITY;
runTest(expressionStrings, order, orderMinimum, orderMaximum, expected, context);
expressionStrings = list("2", "3", "J");
expected = parse("if 3 < J then J else 3");
order = LESS_THAN;
orderMinimum = MINUS_INFINITY;
orderMaximum = INFINITY;
runTest(expressionStrings, order, orderMinimum, orderMaximum, expected, context);
expressionStrings = list("2", "I", "3", "J");
expected = parse("if 2 < I then if I < J then J else I else if 3 < J then J else 3");
order = LESS_THAN;
orderMinimum = MINUS_INFINITY;
orderMaximum = INFINITY;
runTest(expressionStrings, order, orderMinimum, orderMaximum, expected, context);
expressionStrings = list("1", "2");
expected = parse("2");
order = LESS_THAN;
orderMinimum = MINUS_INFINITY;
orderMaximum = INFINITY;
runTest(expressionStrings, order, orderMinimum, orderMaximum, expected, context);
expressionStrings = list("1", "2");
expected = parse("1");
order = GREATER_THAN;
orderMinimum = INFINITY;
orderMaximum = MINUS_INFINITY;
runTest(expressionStrings, order, orderMinimum, orderMaximum, expected, context);
expressionStrings = list("1", "-infinity");
expected = parse("1");
order = LESS_THAN;
orderMinimum = MINUS_INFINITY;
orderMaximum = INFINITY;
runTest(expressionStrings, order, orderMinimum, orderMaximum, expected, context);
expressionStrings = list("1", "infinity");
expected = parse("infinity");
order = LESS_THAN;
orderMinimum = MINUS_INFINITY;
orderMaximum = INFINITY;
runTest(expressionStrings, order, orderMinimum, orderMaximum, expected, context);
}
use of com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.
the class SelectExpressionsSatisfyingComparisonStepSolverTest method test.
@Test
public void test() {
TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new DifferenceArithmeticTheory(true, true));
Context context = theoryTestingSupport.makeContextWithTestingInformation();
List<String> expressionStrings;
Expression bound;
Expression expected;
expressionStrings = list("I", "J");
bound = parse("J");
expected = parse("if I < J then list(I) else list()");
runTest(expressionStrings, bound, expected, context);
expressionStrings = list("I", "2", "J");
bound = parse("3");
expected = parse("if I < 3 then if J < 3 then list(I, 2, J) else list(I, 2) else if J < 3 then list(2, J) else list(2)");
runTest(expressionStrings, bound, expected, context);
expressionStrings = list();
bound = parse("3");
expected = parse("list()");
runTest(expressionStrings, bound, expected, context);
expressionStrings = list("I", "2", "J");
bound = parse("infinity");
expected = parse("list(I, 2, J)");
runTest(expressionStrings, bound, expected, context);
expressionStrings = list("I", "2", "J");
bound = parse("-infinity");
expected = parse("list()");
runTest(expressionStrings, bound, expected, context);
expressionStrings = list("I", "2", "infinity");
bound = parse("3");
expected = parse("if I < 3 then list(I, 2) else list(2)");
runTest(expressionStrings, bound, expected, context);
}
use of com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.
the class CompoundTheoryTestingSupport method aggregateTestingInformation.
//
//
private void aggregateTestingInformation() throws Error {
Map<String, Type> variableNamesAndTypesForTesting = new LinkedHashMap<>();
for (TheoryTestingSupport theoryTestingSupport : getSubConstraintTheoryTestingSupports()) {
Set<Entry<String, Type>> variableNamesAndTypeNameEntries = theoryTestingSupport.getVariableNamesAndTypesForTesting().entrySet();
for (Map.Entry<String, Type> variableNameAndTypeName : variableNamesAndTypeNameEntries) {
String variableName = variableNameAndTypeName.getKey();
Type type = variableNameAndTypeName.getValue();
if (variableNamesAndTypesForTesting.containsKey(variableName)) {
variableName = primedUntilUnique(variableName, s -> variableNamesAndTypesForTesting.containsKey(s.toString()));
}
variableNamesAndTypesForTesting.put(variableName, type);
}
}
setVariableNamesAndTypesForTesting(variableNamesAndTypesForTesting);
}
use of com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.
the class ExpressionStepSolverToLiteralSplitterStepSolverAdapterTest method testPropositionalTheoryWithFixedDisjunctiveFormulas.
@Test
public void testPropositionalTheoryWithFixedDisjunctiveFormulas() {
TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new PropositionalTheory());
extendTestingVaribles("P", theoryTestingSupport, "S", "T");
Context context = theoryTestingSupport.makeContextWithTestingInformation();
runTest(theoryTestingSupport, new GeneralFormulaExpressionTestStepSolver(Expressions.parse("P"), Expressions.parse("Q")), Expressions.parse("if P then if Q then P and Q else P and not Q else if Q then not P and Q else not P and not Q"), context);
runTest(theoryTestingSupport, new GeneralFormulaExpressionTestStepSolver(Expressions.parse("P or Q"), Expressions.parse("R or Q")), Expressions.parse("if P then if R then (P or Q) and (R or Q) else if Q then (P or Q) and (R or Q) else (P or Q) and not (R or Q) else if Q then (P or Q) and (R or Q) else if R then not (P or Q) and (R or Q) else not (P or Q) and not (R or Q)"), context);
runTest(theoryTestingSupport, new GeneralFormulaExpressionTestStepSolver(Expressions.parse("P or Q"), Expressions.parse("R or S")), Expressions.parse("if P then if R then (P or Q) and (R or S) else if S then (P or Q) and (R or S) else (P or Q) and not (R or S) else if Q then if R then (P or Q) and (R or S) else if S then (P or Q) and (R or S) else (P or Q) and not (R or S) else if R then not (P or Q) and (R or S) else if S then not (P or Q) and (R or S) else not (P or Q) and not (R or S)"), context);
}
Aggregations