Search in sources :

Example 41 with CommonTheory

use of com.sri.ai.grinder.application.CommonTheory in project aic-expresso by aic-sri-international.

the class IfThenElseStepSolverTest method test15.

@Test
public void test15() {
    Expression expression = parse("if (X=0) or (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 Z = 1 then 1 else Y + Z else if Y = 1 then if Z = 1 then X + 1 else 1 + Z else 4");
    // get method name as string
    String testName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    runIfThenElseStepSolverTest(expression, context, expectedResult, testName);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonTheory(com.sri.ai.grinder.application.CommonTheory) Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 42 with CommonTheory

use of com.sri.ai.grinder.application.CommonTheory in project aic-expresso by aic-sri-international.

the class IfThenElseStepSolverTest method test10.

@Test
public void test10() {
    Expression expression = parse("if (X=1) or (Y=1) then 2 else 3");
    String[] symbolsAndTypes = { "X", "0..1", "Y", "0..0" };
    Context context = new TrueContext(new CommonTheory()).extendWithSymbolsAndTypes(symbolsAndTypes);
    Expression expectedResult = parse("if X = 1 then 2 else 3");
    // get method name as string
    String testName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    runIfThenElseStepSolverTest(expression, context, expectedResult, testName);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonTheory(com.sri.ai.grinder.application.CommonTheory) Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 43 with CommonTheory

use of com.sri.ai.grinder.application.CommonTheory in project aic-expresso by aic-sri-international.

the class IfThenElseStepSolverTest method test02.

@Test
public void test02() {
    Expression expression = parse("if X=1 then 2 else 3");
    String[] symbolsAndTypes = { "X", "0..1" };
    Context context = new TrueContext(new CommonTheory()).extendWithSymbolsAndTypes(symbolsAndTypes);
    Expression expectedResult = parse("if X = 1 then 2 else 3");
    // get method name as string
    String testName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    runIfThenElseStepSolverTest(expression, context, expectedResult, testName);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonTheory(com.sri.ai.grinder.application.CommonTheory) Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 44 with CommonTheory

use of com.sri.ai.grinder.application.CommonTheory in project aic-expresso by aic-sri-international.

the class IfThenElseStepSolverTest method test13.

@Test
public void test13() {
    Expression expression = parse("if (X=1) and (Y=1) then (X!=1) and (Y!=1) else (X!=1) or (Y!=1)");
    String[] symbolsAndTypes = { "X", "0..1", "Y", "0..1" };
    Context context = new TrueContext(new CommonTheory()).extendWithSymbolsAndTypes(symbolsAndTypes);
    Expression expectedResult = parse("if X = 1 then if Y = 1 then false else true else true");
    // get method name as string
    String testName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    runIfThenElseStepSolverTest(expression, context, expectedResult, testName);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonTheory(com.sri.ai.grinder.application.CommonTheory) Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 45 with CommonTheory

use of com.sri.ai.grinder.application.CommonTheory in project aic-expresso by aic-sri-international.

the class IfThenElseStepSolverTest method test00.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////  JUNIT TESTS  /////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Test
public void test00() {
    Expression expression = parse("if true then 2 else 3");
    Context context = new TrueContext(new CommonTheory());
    Expression expectedResult = parse("2");
    // get method name as string
    String testName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    runIfThenElseStepSolverTest(expression, context, expectedResult, testName);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonTheory(com.sri.ai.grinder.application.CommonTheory) Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Aggregations

Context (com.sri.ai.grinder.api.Context)58 CommonTheory (com.sri.ai.grinder.application.CommonTheory)58 TrueContext (com.sri.ai.grinder.core.TrueContext)58 Expression (com.sri.ai.expresso.api.Expression)55 Test (org.junit.Test)47 Theory (com.sri.ai.grinder.api.Theory)36 Factor (com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)13 ExpressionFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor)13 DefaultExpressionFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor)12 ConstantFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor)11 CompoundTheory (com.sri.ai.grinder.theory.compound.CompoundTheory)9 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)9 EqualityTheory (com.sri.ai.grinder.theory.equality.EqualityTheory)9 LinearRealArithmeticTheory (com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory)9 PropositionalTheory (com.sri.ai.grinder.theory.propositional.PropositionalTheory)9 TupleTheory (com.sri.ai.grinder.theory.tuple.TupleTheory)9 DefaultExpressionVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionVariable)7 ExpressionVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionVariable)5 ExpressionFactorNetwork (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.ExpressionFactorNetwork)4 ArrayList (java.util.ArrayList)3