use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class SampleCommonInterpreterTest method runTest.
public void runTest(int sampleSizeN, boolean alwaysSample, String expressionString, String expectedString) {
Expression expected = parse(expectedString);
Expression actual = run(sampleSizeN, alwaysSample, expressionString);
Assert.assertEquals(expected, actual);
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class SampleCommonInterpreterTest method runBoundedTest.
public void runBoundedTest(int sampleSizeN, boolean alwaysSample, String expressionString, String lowerBoundInclusiveString, String upperBoundInclusiveString) {
Expression lowerBoundInclusive = context.getTheory().evaluate(parse(lowerBoundInclusiveString), context);
Expression upperBoundInclusive = context.getTheory().evaluate(parse(upperBoundInclusiveString), context);
Expression actual = run(sampleSizeN, alwaysSample, expressionString);
System.out.println("upper bound = " + upperBoundInclusive.doubleValue() + " (as rational=" + toString(upperBoundInclusive) + ")");
System.out.println(" actual = " + actual.doubleValue() + " (as rational=" + toString(actual) + ")");
System.out.println("lower bound = " + lowerBoundInclusive.doubleValue() + " (as rational=" + toString(lowerBoundInclusive) + ")");
Assert.assertTrue("actual (" + toString(actual) + ") is not >= lower bound (" + toString(lowerBoundInclusive) + ")", actual.compareTo(lowerBoundInclusive) >= 0);
Assert.assertTrue("actual (" + toString(actual) + ") is not <= upper bound (" + toString(upperBoundInclusive) + ")", actual.compareTo(upperBoundInclusive) <= 0);
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class IntensionalUnionToUnionsOfIntensionalSetsOfBaseTypeSimplifierTest method testBaseCase.
@Test
public void testBaseCase() {
Expression baseCase = parse("Union({{(on I in 1..10) {(I, 2)} : I != 5}})");
Assert.assertEquals(parse("{{(on I in 1..10) (I, 2) : I != 5}}"), simplifier.apply(baseCase, context));
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class IntersectionExtensionalSetSimplifierTest method testExtensionalInExtensonalBasicCases.
@Test
public void testExtensionalInExtensonalBasicCases() {
Expression intersection = parse("{(2,2),(3,2),(4,2)} intersection {}");
Assert.assertEquals(parse("{}"), simplifier.apply(intersection, context));
parse("{} intersection {(2,2),(3,2),(4,2)}");
Assert.assertEquals(parse("{}"), simplifier.apply(intersection, context));
intersection = parse("{(2,2),(3,2),(4,2)} intersection {(2,2),(3,2),(5,2),(6,2)}");
Assert.assertEquals(parse("{(2,2)} union {(3,2)}"), simplifier.apply(intersection, context));
intersection = parse("{(2,2),(3,2),(4,2)} intersection {(N, 2)}");
Assert.assertEquals(parse("(if 2 = N then {(2,2)} else {}) union (if 3 = N then {(3,2)} else {}) union (if 4 = N then {(4,2)} else {})"), simplifier.apply(intersection, context));
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class InversionPerformanceEvaluationTest method evaluate.
private Pair<Long, Expression> evaluate(Expression sumProduct, SumProductInterpreter sumProductInterpreter) {
long start = System.currentTimeMillis();
Expression evalResult = sumProductInterpreter.apply(sumProduct, context);
long duration = System.currentTimeMillis() - start;
Pair<Long, Expression> result = new Pair<>(duration, evalResult);
return result;
}
Aggregations