Пример #1
0
        public void testANDRule()
        {
            Rule r = new Rule(new ANDCondition(new EQUALCondition(
                    ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true), new EQUALCondition(
                    ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, true)),
                    ACTION_EMERGENCY_BRAKING);

            Assert.Equals(ACTION_EMERGENCY_BRAKING, r.getAction());

            Assert
                    .Equals(
                            "if [car-in-front-is-braking==true && car-in-front-tires-smoking==true] then Action[name==emergency-braking].",
                            r.ToString());

            Assert.Equals(false, r.evaluate(new DynamicPercept(
                    ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true)));

            Assert.Equals(false, r.evaluate(new DynamicPercept(
                    ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, true)));

            Assert.Equals(true, r.evaluate(new DynamicPercept(
                    ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true,
                    ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, true)));

            Assert.Equals(false, r.evaluate(new DynamicPercept(
                    ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, false,
                    ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, true)));

            Assert.Equals(false, r.evaluate(new DynamicPercept(
                    ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true,
                    ATTRIBUTE_CAR_IN_FRONT_TIRES_SMOKING, false)));
        }
Пример #2
0
        public void testNOTRule()
        {
            Rule r = new Rule(new NOTCondition(new EQUALCondition(
                    ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true)),
                    ACTION_INITIATE_BRAKING);

            Assert.Equals(ACTION_INITIATE_BRAKING, r.getAction());

            Assert.Equals(
                            "if ![car-in-front-is-braking==true] then Action[name==initiate-braking].",
                            r.ToString());

            Assert.Equals(false, r.evaluate(new DynamicPercept(
                    ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, true)));

            Assert.Equals(true, r.evaluate(new DynamicPercept(
                    ATTRIBUTE_CAR_IN_FRONT_IS_BRAKING, false)));

            Assert.Equals(true, r.evaluate(new DynamicPercept(
                    ATTRIBUTE_CAR_IN_FRONT_IS_INDICATING, true)));
        }
	protected Action ruleAction(Rule r) {
		return null == r ? NoOpAction.NO_OP : r.getAction();
	}