Search in sources :

Example 61 with Type

use of com.sri.ai.expresso.api.Type in project aic-expresso by aic-sri-international.

the class EvaluationTest method testEvaluationOfCardinalityExpressions.

@Test
public void testEvaluationOfCardinalityExpressions() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, true), new PropositionalTheory()));
    Map<String, Type> variablesAndTypes = new LinkedHashMap<>(theoryTestingSupport.getVariableNamesAndTypesForTesting());
    Type booleanType = variablesAndTypes.get("P");
    variablesAndTypes.put("S", booleanType);
    variablesAndTypes.put("T", booleanType);
    variablesAndTypes.put("U", booleanType);
    theoryTestingSupport.setVariableNamesAndTypesForTesting(variablesAndTypes);
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    String expressionString;
    Expression expected;
    expressionString = "| {{ (on I in 1..10) 3 : I != 4 and P }} |";
    expected = parse("if P then 9 else 0");
    runTest(expressionString, expected, context);
    expressionString = "| I in 1..10 : I != 4 and P |";
    expected = parse("if P then 9 else 0");
    runTest(expressionString, expected, context);
    expressionString = "| {{ (on ) 3 : I != 4 and P }} |";
    expected = parse("if I != 4 then if P then 1 else 0 else 0");
    runTest(expressionString, expected, context);
    expressionString = "| : I != 4 and P |";
    expected = parse("if I != 4 then if P then 1 else 0 else 0");
    runTest(expressionString, expected, context);
    expressionString = "| {{ (on ) 3 : P and not P }} |";
    expected = parse("0");
    runTest(expressionString, expected, context);
    expressionString = "| : P and not P |";
    expected = parse("0");
    runTest(expressionString, expected, context);
    expressionString = "| {{ (on I in 1..10, J in 1..2) 3 : I != 4 }} |";
    expected = parse("18");
    runTest(expressionString, expected, context);
    expressionString = "| I in 1..10, J in 1..2 : I != 4 |";
    expected = parse("18");
    runTest(expressionString, expected, context);
    expressionString = "| {{ (on I in 1..10, P in Boolean) 3 : I != 4 }} |";
    expected = parse("18");
    runTest(expressionString, expected, context);
    expressionString = "| I in 1..10, P in Boolean: I != 4 |";
    expected = parse("18");
    runTest(expressionString, expected, context);
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) Type(com.sri.ai.expresso.api.Type) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

Type (com.sri.ai.expresso.api.Type)61 Expression (com.sri.ai.expresso.api.Expression)47 Context (com.sri.ai.grinder.sgdpllt.api.Context)21 FunctionType (com.sri.ai.expresso.type.FunctionType)17 Test (org.junit.Test)14 Categorical (com.sri.ai.expresso.type.Categorical)13 RealExpressoType (com.sri.ai.expresso.type.RealExpressoType)12 TupleType (com.sri.ai.expresso.type.TupleType)12 Map (java.util.Map)12 TheoryTestingSupport (com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport)11 LinkedHashMap (java.util.LinkedHashMap)11 IntegerExpressoType (com.sri.ai.expresso.type.IntegerExpressoType)10 IntegerInterval (com.sri.ai.expresso.type.IntegerInterval)10 ArrayList (java.util.ArrayList)10 IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)9 RealInterval (com.sri.ai.expresso.type.RealInterval)8 Beta (com.google.common.annotations.Beta)7 Registry (com.sri.ai.grinder.api.Registry)7 DifferenceArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory)7 IntensionalSet (com.sri.ai.expresso.api.IntensionalSet)6