use of com.sri.ai.grinder.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.
the class SummationOnDifferenceArithmeticAndPolynomialStepSolverTest method polynomialBodyWithADifferentVariableTest.
@Test
public void polynomialBodyWithADifferentVariableTest() {
TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new DifferenceArithmeticTheory(true, true));
Context context = theoryTestingSupport.makeContextWithTestingInformation();
Expression variable;
String constraintString;
Expression body;
Expression expected;
variable = parse("I");
body = parse("I^2 - J + 1");
constraintString = "true";
expected = parse("-(5*J) + 35");
runTest(variable, constraintString, body, expected, context);
constraintString = "I != 3";
expected = parse("-(4*J) + 25");
runTest(variable, constraintString, body, expected, context);
constraintString = "I < 3";
expected = parse("-(3*J) + 8");
runTest(variable, constraintString, body, expected, context);
constraintString = "false";
expected = parse("0");
runTest(variable, constraintString, body, expected, context);
constraintString = "I > 3 and I < 3";
expected = parse("0");
runTest(variable, constraintString, body, expected, context);
constraintString = "I > 1 and I < 3 and I != 2";
expected = parse("0");
runTest(variable, constraintString, body, expected, context);
}
use of com.sri.ai.grinder.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.
the class SummationOnDifferenceArithmeticAndPolynomialStepSolverTest method polynomialBodyAndConstraintWithADifferentVariableTest.
@Test
public void polynomialBodyAndConstraintWithADifferentVariableTest() {
TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new DifferenceArithmeticTheory(true, true));
Context context = theoryTestingSupport.makeContextWithTestingInformation();
Expression variable;
String constraintString;
Expression body;
Expression expected;
variable = parse("I");
body = parse("I^2 - J + 1");
constraintString = "I != J";
expected = parse("-(J^2) -(4*J) + 34");
runTest(variable, constraintString, body, expected, context);
constraintString = "I <= J and I != J";
expected = parse("(1/3 * J ^ 3 - 1.5 * J ^ 2) + 7/6 * J");
runTest(variable, constraintString, body, expected, context);
constraintString = "I < J and I > J";
expected = parse("0");
runTest(variable, constraintString, body, expected, context);
}
use of com.sri.ai.grinder.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.
the class AbstractEqualityConstraintTest method testSatisfiabilitySpecialCases.
@Test
public void testSatisfiabilitySpecialCases() {
String conjunction;
// looks unsatisfiable for type size 5, but it is not
conjunction = "X != a and X != b and X != c and X != Y and X != Z";
TheoryTestingSupport theoryTestingSupport = makeTheoryTestingSupport();
Constraint constraint = new SingleVariableEqualityConstraint(parse("X"), false, theoryTestingSupport.getTheory());
Context context = theoryTestingSupport.makeContextWithTestingInformation();
constraint = constraint.conjoinWithConjunctiveClause(parse(conjunction), context);
// satisfiable if either Y or Z is equal to a, b, c, or each other.
Assert.assertNotEquals(null, constraint);
}
use of com.sri.ai.grinder.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.
the class AbstractEqualityConstraintTest method runCompleteSatisfiabilityTest.
/**
* @param conjunction
* @param expected
*/
private void runCompleteSatisfiabilityTest(String conjunction, Expression expected, TheoryTestingSupport theoryTestingSupport) {
Context context = theoryTestingSupport.makeContextWithTestingInformation();
Constraint constraint = new CompleteMultiVariableContext(theoryTestingSupport.getTheory(), context);
for (Expression literal : And.getConjuncts(parse(conjunction))) {
constraint = constraint.conjoin(literal, context);
if (constraint.isContradiction()) {
break;
}
}
if (expected == null && !constraint.isContradiction()) {
throw new AssertionError("Expected null but was <" + constraint + ">");
} else if (expected != null && constraint.isContradiction()) {
throw new AssertionError("Expected <" + expected + "> but was null");
} else if (expected != null && !constraint.isContradiction() && !expected.equals(constraint)) {
Simplifier interpreter = (e, c) -> theoryTestingSupport.getTheory().evaluate(e, c);
// Simplifier interpreter = new Evaluator(theoryTestingSupport.getTheory());
Expression equivalenceDefinition = apply(EQUIVALENCE, expected, constraint);
Expression universallyQuantified = universallyQuantifyFreeVariables(equivalenceDefinition, context);
Expression equivalent = interpreter.apply(universallyQuantified, context);
if (equivalent.equals(FALSE)) {
throw new Error("Expected <" + expected + "> but got <" + constraint + ">, which is not equivalent either");
}
}
}
use of com.sri.ai.grinder.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);
}
Aggregations