public void RuleThatAlwaysFiresTest()
        {
            var underTest = new ProductionRuleEngine <TestContext>(new List <IProductionRule <TestContext> >()
            {
                new RuleThatAlwaysFires()
            });
            var blankContext = new TestContext();

            underTest.Run(blankContext);
            Assert.IsTrue(blankContext.IsHot == false);
        }
        public void NoInferenceOnNullValues()
        {
            var underTest = new ProductionRuleEngine <TestContext>(new List <IProductionRule <TestContext> >()
            {
                new TestRule()
            });
            var blankContext = new TestContext();

            underTest.Run(blankContext);
            Assert.IsTrue(blankContext.IsHappy.HasValue == false);
        }
        public void ReEvaluateRule()
        {
            var underTest = new ProductionRuleEngine <TestContext>(new List <IProductionRule <TestContext> >()
            {
                new WhenHappyRule(), new WhenBirdsSingingRule()
            });
            var context = new TestContext()
            {
                IsSunShining = false, IsDawn = true
            };

            underTest.Run(context);
            Assert.IsTrue(context.IsHappy == true);
        }
        public void HigherSalienceRulesOverride()
        {
            var underTest = new ProductionRuleEngine <TestContext>(new List <IProductionRule <TestContext> >()
            {
                new TestRule(), new ConflictingRule1()
            });
            var blankContext = new TestContext()
            {
                IsSunShining = false
            };

            underTest.Run(blankContext);
            Assert.IsTrue(blankContext.IsHappy == true);
        }
        public void Inference()
        {
            var underTest = new ProductionRuleEngine <TestContext>(new List <IProductionRule <TestContext> >()
            {
                new TestRule()
            });
            var blankContext = new TestContext()
            {
                IsSunShining = true
            };

            underTest.Run(blankContext);
            Assert.IsTrue(blankContext.IsHappy == true);
        }
        static void Main(string[] args)
        {
            var context = new Context();

            // rules
            var re = new ProductionRuleEngine <Context>(new List <IProductionRule <Context> >()
            {
                new SunShiningRule(), new SuperNovaRule()
            });

            var screen1 = new SimpleWizard.QuestionScreen <Context>()
            {
                QuestionText  = "Shining?",
                QuestionType  = typeof(bool),
                ReflectAnswer = (a, c) => c.IsSunShining = (bool)a
            };

            var screen2 = new SimpleWizard.QuestionScreen <Context>()
            {
                QuestionText  = "Likes sun?",
                QuestionType  = typeof(bool),
                ReflectAnswer = (a, c) => c.PersonLikesSun = (bool)a
            };

            var screen3 = new QuestionScreen <Context>()
            {
                QuestionText  = "Sun gone nova?",
                QuestionType  = typeof(bool),
                ReflectAnswer = (a, c) => c.SunGoneNova = (bool)a
            };

            var edge = new ScreenLink <Context>()
            {
                Source = screen1, Target = screen2, TraverseCondition = c => !c.IsPersonHappy.HasValue
            };
            var edge2 = new ScreenLink <Context>()
            {
                Source = screen2, Target = screen3, TraverseCondition = c => c.IsPersonHappy == true
            };

            var wm = new WizardManager <Context>(new[] { screen1, screen2, screen3 }, new[] { edge, edge2 }, c => re.Run(c));

            var cc = new ConsoleWizardClient <Context>(wm, context);

            cc.Start();
            var outcome = context.IsPersonHappy;

            Console.WriteLine("Outcome: " + outcome);
            Console.ReadKey();
        }
        public void TestTracing()
        {
            var underTest = new ProductionRuleEngine <TestContext>(new List <IProductionRule <TestContext> >()
            {
                new TestRule()
            });
            var blankContext = new TestContext()
            {
                IsSunShining = true
            };

            underTest.Run(blankContext);
            var log = underTest.Log;

            Assert.IsTrue(log.Count() == 1);
            Assert.IsTrue(log.First().Before.IsHappy.HasValue == false);
            Assert.IsTrue(log.First().After.IsHappy.HasValue == true);
        }