use of com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.
the class UnificationStepSolverTest method equalityTest.
@Test
public void equalityTest() {
TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(seededRandom, new EqualityTheory(true, true));
// NOTE: passing explicit FunctionTypes will prevent the general variables' argument types being randomly changed.
theoryTestingSupport.setVariableNamesAndTypesForTesting(map("X", TESTING_CATEGORICAL_TYPE, "Y", TESTING_CATEGORICAL_TYPE, "Z", TESTING_CATEGORICAL_TYPE, "unary_eq", new FunctionType(TESTING_CATEGORICAL_TYPE, TESTING_CATEGORICAL_TYPE), "binary_eq", new FunctionType(TESTING_CATEGORICAL_TYPE, TESTING_CATEGORICAL_TYPE, TESTING_CATEGORICAL_TYPE)));
Context rootContext = theoryTestingSupport.makeContextWithTestingInformation();
UnificationStepSolver unificationStepSolver = new UnificationStepSolver(parse("unary_eq(X)"), parse("unary_eq(X)"));
StepSolver.Step<Boolean> step = unificationStepSolver.step(rootContext);
Assert.assertEquals(false, step.itDepends());
Assert.assertEquals(true, step.getValue());
unificationStepSolver = new UnificationStepSolver(parse("unary_eq(X)"), parse("unary_eq(Y)"));
step = unificationStepSolver.step(rootContext);
Assert.assertEquals(true, step.itDepends());
Assert.assertEquals(Expressions.parse("X = Y"), step.getSplitter());
Assert.assertEquals(false, step.getStepSolverForWhenSplitterIsTrue().step(rootContext).itDepends());
Assert.assertEquals(true, step.getStepSolverForWhenSplitterIsTrue().step(rootContext).getValue());
Assert.assertEquals(false, step.getStepSolverForWhenSplitterIsFalse().step(rootContext).itDepends());
Assert.assertEquals(false, step.getStepSolverForWhenSplitterIsFalse().step(rootContext).getValue());
Context localTestContext = rootContext.conjoinWithConjunctiveClause(parse("X = a and Y = b"), rootContext);
step = unificationStepSolver.step(localTestContext);
Assert.assertEquals(false, step.itDepends());
Assert.assertEquals(false, step.getValue());
unificationStepSolver = new UnificationStepSolver(parse("unary_eq(X)"), parse("unary_eq(a)"));
localTestContext = rootContext.conjoinWithConjunctiveClause(parse("X = a"), rootContext);
step = unificationStepSolver.step(localTestContext);
Assert.assertEquals(false, step.itDepends());
Assert.assertEquals(true, step.getValue());
localTestContext = rootContext.conjoinWithConjunctiveClause(parse("X = b"), rootContext);
step = unificationStepSolver.step(localTestContext);
Assert.assertEquals(false, step.itDepends());
Assert.assertEquals(false, step.getValue());
unificationStepSolver = new UnificationStepSolver(parse("binary_eq(X, unary_eq(X))"), parse("binary_eq(unary_eq(Y), Y)"));
step = unificationStepSolver.step(rootContext);
Assert.assertEquals(true, step.itDepends());
Assert.assertEquals(Expressions.parse("X = unary_eq(Y)"), step.getSplitter());
}
use of com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.
the class UnificationStepSolverTest method advancedEqualityTest.
@Ignore("TODO - context implementation currently does not support these more advanced/indirect comparisons")
@Test
public void advancedEqualityTest() {
TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(seededRandom, new EqualityTheory(false, true));
// NOTE: passing explicit FunctionTypes will prevent the general variables' argument types being randomly changed.
theoryTestingSupport.setVariableNamesAndTypesForTesting(map("X", TESTING_CATEGORICAL_TYPE, "Y", TESTING_CATEGORICAL_TYPE, "Z", TESTING_CATEGORICAL_TYPE, "unary_eq/1", new FunctionType(TESTING_CATEGORICAL_TYPE, TESTING_CATEGORICAL_TYPE), "binary_eq/2", new FunctionType(TESTING_CATEGORICAL_TYPE, TESTING_CATEGORICAL_TYPE, TESTING_CATEGORICAL_TYPE)));
Context rootContext = theoryTestingSupport.makeContextWithTestingInformation();
UnificationStepSolver unificationStepSolver = new UnificationStepSolver(parse("binary_eq(X, unary_eq(X))"), parse("binary_eq(unary_eq(Y), Y)"));
Context localTestContext = rootContext.conjoinWithConjunctiveClause(parse("X = b and Y = a and unary_eq(Y) = b and unary_eq(X) = a"), rootContext);
StepSolver.Step<Boolean> step = unificationStepSolver.step(localTestContext);
Assert.assertEquals(false, step.itDepends());
Assert.assertEquals(true, step.getValue());
localTestContext = rootContext.conjoinWithConjunctiveClause(parse("X = a and Y = a and unary_eq(Y) = b and unary_eq(X) = a"), rootContext);
step = unificationStepSolver.step(localTestContext);
Assert.assertEquals(false, step.itDepends());
Assert.assertEquals(false, step.getValue());
localTestContext = rootContext.conjoinWithConjunctiveClause(parse("X = b and Y = a and unary_eq(a) = b and unary_eq(b) = a"), rootContext);
step = unificationStepSolver.step(localTestContext);
Assert.assertEquals(false, step.itDepends());
Assert.assertEquals(true, step.getValue());
}
use of com.sri.ai.grinder.sgdpllt.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("-1*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.sgdpllt.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.
the class SummationOnDifferenceArithmeticAndPolynomialStepSolverTest method simpleBodyTest.
@Test
public void simpleBodyTest() {
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");
constraintString = "true";
expected = parse("10");
runTest(variable, constraintString, body, expected, context);
constraintString = "I != 3";
expected = parse("7");
runTest(variable, constraintString, body, expected, context);
constraintString = "I < 3";
expected = parse("3");
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.sgdpllt.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);
}
Aggregations