use of com.sri.ai.grinder.application.CommonTheory in project aic-expresso by aic-sri-international.
the class GrinderTest method testPastBugs.
@Test
public void testPastBugs() {
Expression expression;
Expression actual;
Expression expected;
Context context;
// Previously, all equalities were being simplified by linear real arithmetic and different arithmetic theories
// as if they were literals.
// In the examples below, this led to (if I > 3 then X else Y) = Y being treated as a literal but then generating an exception
// (since it does not conform to the properties expected from a literal).
// This has been fixed by adding a check "isLiteral".
context = new TrueContext(new CommonTheory());
context = context.extendWithSymbolsAndTypes("X", "Real", "Y", "Real");
expression = parse("there exists I in 1..5 : (if I > 3 then X else Y) = Y");
expected = parse("true");
actual = context.evaluate(expression);
assertEquals(expected, actual);
context = new TrueContext(new CommonTheory());
context = context.extendWithSymbolsAndTypes("J", "Integer", "K", "Integer");
expression = parse("there exists I in 1..5 : (if I > 3 then J else K) = K");
expected = parse("true");
actual = context.evaluate(expression);
assertEquals(expected, actual);
context = new TrueContext(new CommonTheory());
context = context.extendWithSymbolsAndTypes("I", "Integer", "X", "Real", "Y", "Real");
expression = parse("(if I > 3 then X else Y) = Y");
expected = parse("if I > 3 then X = Y else true");
actual = context.evaluate(expression);
assertEquals(expected, actual);
context = new TrueContext(new CommonTheory());
context = context.extendWithSymbolsAndTypes("I", "Integer", "J", "Integer", "K", "Integer");
expression = parse("(if I > 3 then J else K) = K");
expected = parse("if I > 3 then J = K else true");
actual = context.evaluate(expression);
assertEquals(expected, actual);
}
use of com.sri.ai.grinder.application.CommonTheory in project aic-expresso by aic-sri-international.
the class IfThenElseStepSolverTest method test14.
@Test
public void test14() {
Expression expression = parse("if (X=0) and (Y=1) then if (Z = 1) then (X + Z) else (Y + Z) else 4");
String[] symbolsAndTypes = { "X", "0..1", "Y", "0..1", "Z", "0..1" };
Context context = new TrueContext(new CommonTheory()).extendWithSymbolsAndTypes(symbolsAndTypes);
Expression expectedResult = parse("if X = 0 then if Y = 1 then if Z = 1 then 1 else 1 + Z else 4 else 4");
// get method name as string
String testName = new Object() {
}.getClass().getEnclosingMethod().getName();
runIfThenElseStepSolverTest(expression, context, expectedResult, testName);
}
use of com.sri.ai.grinder.application.CommonTheory in project aic-expresso by aic-sri-international.
the class IfThenElseStepSolverTest method test03.
@Test
public void test03() {
Expression expression = parse("if X=1 then 2 else 3");
String[] symbolsAndTypes = { "X", "1..1" };
Context context = new TrueContext(new CommonTheory()).extendWithSymbolsAndTypes(symbolsAndTypes);
Expression expectedResult = parse("2");
// get method name as string
String testName = new Object() {
}.getClass().getEnclosingMethod().getName();
runIfThenElseStepSolverTest(expression, context, expectedResult, testName);
}
use of com.sri.ai.grinder.application.CommonTheory in project aic-expresso by aic-sri-international.
the class IfThenElseStepSolverTest method test07.
@Test
public void test07() {
Expression expression = parse("if (X=1) or (Y=1) then 2 else 3");
String[] symbolsAndTypes = { "X", "1..1", "Y", "0..1" };
Context context = new TrueContext(new CommonTheory()).extendWithSymbolsAndTypes(symbolsAndTypes);
Expression expectedResult = parse("2");
// get method name as string
String testName = new Object() {
}.getClass().getEnclosingMethod().getName();
runIfThenElseStepSolverTest(expression, context, expectedResult, testName);
}
use of com.sri.ai.grinder.application.CommonTheory in project aic-expresso by aic-sri-international.
the class IfThenElseStepSolverTest method test08.
@Test
public void test08() {
Expression expression = parse("if (X=1) or (Y=1) then 2 else 3");
String[] symbolsAndTypes = { "X", "0..0", "Y", "0..1" };
Context context = new TrueContext(new CommonTheory()).extendWithSymbolsAndTypes(symbolsAndTypes);
Expression expectedResult = parse("if Y = 1 then 2 else 3");
// get method name as string
String testName = new Object() {
}.getClass().getEnclosingMethod().getName();
runIfThenElseStepSolverTest(expression, context, expectedResult, testName);
}
Aggregations