ParseRule() public method

public ParseRule ( ) : Rule
return AjRools.Expert.Rules.Rule
Example #1
0
        public void ParseSimpleConditionRule()
        {
            Parser parser = new Parser(new StreamReader("SimpleComparisonRule.txt"));

            Rule rule = parser.ParseRule();

            Assert.IsNotNull(rule);

            Assert.IsTrue(rule.Conditions.Contains(new ComparisonFact("Temperature", Comparison.Greater, 37)));
            Assert.IsTrue(rule.Assertions.Contains(new IsFact("HasFever", true)));

            Assert.IsNull(parser.ParseRule());
        }
Example #2
0
        public void ParseSimpleRule()
        {
            Parser parser = new Parser("rule\r\nwhen\r\nTemperature is 39\r\nthen\r\nHasFever is true\r\nend");

            Rule rule = parser.ParseRule();

            Assert.IsNotNull(rule);

            Assert.IsTrue(rule.Conditions.Contains(new IsFact("Temperature", 39)));
            Assert.IsTrue(rule.Assertions.Contains(new IsFact("HasFever", true)));
        }
Example #3
0
        public void ParseRuleWithString()
        {
            Parser parser = new Parser("rule\r\nwhen\r\nTemperatureLevel is \"High\"\r\nthen\r\nHasFever is true\r\nend\r\n");

            Rule rule = parser.ParseRule();

            Assert.IsNotNull(rule);

            Assert.IsTrue(rule.Conditions.Contains(new IsFact("TemperatureLevel", "High")));
            Assert.IsTrue(rule.Assertions.Contains(new IsFact("HasFever", true)));
        }
Example #4
0
        public void ParseRuleWithComparisonFact()
        {
            Parser parser = new Parser("rule\r\nwhen\r\nTemperatureLevel >= 38\r\nthen\r\nHasFever is true\r\nend\r\n");

            Rule rule = parser.ParseRule();

            Assert.IsNotNull(rule);

            Assert.IsTrue(rule.Conditions.Contains(new ComparisonFact("TemperatureLevel", Comparison.GreaterEqual, 38)));
            Assert.IsTrue(rule.Assertions.Contains(new IsFact("HasFever", true)));
        }
Example #5
0
        public void ParseSimpleRuleFileWithIsNotCondition()
        {
            Parser parser = new Parser(new StreamReader("SimpleRuleWithIsNotCondition.txt"));

            Rule rule = parser.ParseRule();

            Assert.IsNotNull(rule);

            Assert.IsTrue(rule.Conditions.Contains(new IsNotFact("Temperature", 39)));
            Assert.IsTrue(rule.Assertions.Contains(new IsFact("HasFever", true)));

            Assert.IsNull(parser.ParseRule());
        }
Example #6
0
 public void RaiseWhenVerbIsANumber()
 {
     Parser parser = new Parser("rule\r\nwhen\r\na 1 b\r\nthen\r\na\r\nend");
     MyAssert.Throws<LexerException>(() => parser.ParseRule(),
     "Unexpected '1'");
 }
Example #7
0
 public void RaiseWhenUnknownVerb()
 {
     Parser parser = new Parser("rule\r\nwhen\r\na foo b");
     MyAssert.Throws<LexerException>(() => parser.ParseRule(),
     "Unexpected 'foo'");
 }
Example #8
0
 public void RaiseWhenUnexpectedValueInCondition()
 {
     Parser parser = new Parser("rule\r\nwhen\r\na is <=");
     MyAssert.Throws<LexerException>(() => parser.ParseRule(),
     "Unexpected '<='");
 }
Example #9
0
 public void RaiseWhenNoWhenInRule()
 {
     Parser parser = new Parser("rule\r\n1 is a");
     MyAssert.Throws<LexerException>(() => parser.ParseRule(),
     "Expected 'when'");
 }
Example #10
0
 public void RaiseWhenTwoManyWordsInCondition()
 {
     Parser parser = new Parser("rule\r\nwhen\r\na is 48 c");
     MyAssert.Throws<LexerException>(() => parser.ParseRule(), "Expected End of Line/Input");
 }
Example #11
0
 public void RaiseWhenNoValueInCondition()
 {
     Parser parser = new Parser("rule\r\nwhen\r\na is");
     MyAssert.Throws<LexerException>(() => parser.ParseRule(),
     "Unexpected End of Input");
 }
Example #12
0
 public void RaiseWhenNoRule()
 {
     Parser parser = new Parser(new StringReader("foo"));
     MyAssert.Throws<LexerException>(() => parser.ParseRule(),
     "Expected 'rule'");
 }
Example #13
0
 public void RaiseWhenNoNameAtStartOfCondition()
 {
     Parser parser = new Parser("rule\r\nwhen\r\n1 is a");
     MyAssert.Throws<LexerException>(() => parser.ParseRule(),
     "Expected Name");
 }
Example #14
0
        public void ParseSimpleRuleWithObjectVariable()
        {
            Parser parser = new Parser(new StreamReader("SimpleRuleWithObjectVariable.txt"));

            Rule rule = parser.ParseRule();

            Assert.AreEqual(2, rule.Conditions.Count());
            Assert.AreEqual(1, rule.Assertions.Count());
        }
Example #15
0
 private void AddRule(string filename)
 {
     Parser parser = new Parser(new StreamReader(filename));
     Rule rule = parser.ParseRule();
     this.world.AddRule(rule);
 }