Search in sources :

Example 1 with ORCondition

use of aima.core.agent.impl.aprog.simplerule.ORCondition in project aima-java by aimacode.

the class RuleTest method testORRule.

@Test
public void testORRule() {
    Rule r = new Rule(new ORCondition(new EQUALCondition(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true), new EQUALCondition(ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, true)), ACTION_EMERGENCY_BRAKING);
    Assert.assertEquals(ACTION_EMERGENCY_BRAKING, r.getAction());
    Assert.assertEquals("if [car-in-front-is-braking==true || car-in-front-tires-smoking==true] then Action[name==emergency-braking].", r.toString());
    Assert.assertEquals(true, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true)));
    Assert.assertEquals(true, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, true)));
    Assert.assertEquals(true, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true, ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, true)));
    Assert.assertEquals(true, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, false, ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, true)));
    Assert.assertEquals(true, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true, ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, false)));
    Assert.assertEquals(false, r.evaluate(new DynamicPercept(ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, false, ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, false)));
}
Also used : DynamicPercept(aima.core.agent.impl.DynamicPercept) EQUALCondition(aima.core.agent.impl.aprog.simplerule.EQUALCondition) Rule(aima.core.agent.impl.aprog.simplerule.Rule) ORCondition(aima.core.agent.impl.aprog.simplerule.ORCondition) Test(org.junit.Test)

Aggregations

DynamicPercept (aima.core.agent.impl.DynamicPercept)1 EQUALCondition (aima.core.agent.impl.aprog.simplerule.EQUALCondition)1 ORCondition (aima.core.agent.impl.aprog.simplerule.ORCondition)1 Rule (aima.core.agent.impl.aprog.simplerule.Rule)1 Test (org.junit.Test)1