public void EasyRuleDymeParser_GivenBothJunctiveDymeRules_ExpectEasyRules()
        {
            // Arrange...
            var sut            = new EasyRuleDymeRuleConverter();
            var expectEasyRule = "IF (age) IS (10) OR (genre) IS (cartoon) THEN (movie) IS (visible) AND (there) NOT (violence)";
            var inputDymeRule  =
                If.When(Any.Of
                            (ItsAFact.That("age").Is("10"))
                        .Or
                            (ItsAFact.That("genre").Is("cartoon"))
                        .IsTrue())
                .Then(All.Of
                          (ItsAFact.That("movie").Is("visible"))
                      .And
                          (ItsAFact.That("there").IsNot("violence"))
                      .IsTrue());
            // Act...
            var result = sut.ConvertDymeRuleToEasyRule(inputDymeRule);

            Assert.AreEqual(expectEasyRule, result);
        }
        public void GetRulesForWorlds_GivenWorlds_ExpectRuleSetFor3Worlds()
        {
            // Arrange...
            var jsonWorlds = new List <string>();

            jsonWorlds.Add("{'Name':'Bob', 'Age':'40', 'Year': '2040'}");
            jsonWorlds.Add("{'Name':'Bob', 'Age':'30', 'Year': '2030'}");
            jsonWorlds.Add("{'Name':'Sam', 'Age':'30', 'Year': '2030'}");
            jsonWorlds.Add("{'Name':'Tom', 'Age':'30', 'Year': '2010'}");

            var sut      = new DymeInferenceEvaluator(_worldReader, _worldAnalyser);
            var expected = new List <IEvaluatable>();

            expected.Add(If.When(ItsAFact.That("Year").Is("2030")).Then(ItsAFact.That("Age").Is("30")));

            // Act...
            var results = sut.GetRulesForWorlds(jsonWorlds, InferenceMethod.Pessimistic);

            // Assert...
            CollectionAssert.AreEquivalent(expected, results);
        }
        public void PessimisticWorld_GivenWorlds2_ExpectRuleSet()
        {
            // Arrange...
            var jsonWorlds = new List <string>();

            jsonWorlds.Add("{'planet':'Earth', 'sky':'blue', 'ground': 'soft', 'cat': 'InCharge'}");
            jsonWorlds.Add("{'planet':'Venus', 'sky':'yellow', 'ground': 'hard', 'cat': 'InCharge'}");
            jsonWorlds.Add("{'planet':'Mars', 'sky':'red', 'ground': 'soft', 'cat': 'InCharge'}");
            jsonWorlds.Add("{'planet':'Pluto', 'sky':'blue', 'ground': 'soft', 'cat': 'InCharge'}");

            var sut      = new DymeInferenceEvaluator(_worldReader, _worldAnalyser);
            var expected = new List <IEvaluatable>();

            expected.Add(If.When(ItsAFact.That("sky").Is("blue")).Then(ItsAFact.That("ground").Is("soft")));

            // Act...
            var results = sut.GetRulesForWorlds(jsonWorlds, InferenceMethod.Pessimistic);

            // Assert...
            CollectionAssert.AreEquivalent(expected, results);
        }
        public void MergeImplications_Given3ImplicationsSameConsequent_ExpectMergedImplication()
        {
            // Arrange...
            var input = new List <IEvaluatable>();

            input.Add(If.When(ItsAFact.That("sky").Is("blue")).Then(ItsAFact.That("ground").Is("soft")));
            input.Add(If.When(ItsAFact.That("sky").Is("red")).Then(ItsAFact.That("ground").Is("soft")));
            input.Add(If.When(ItsAFact.That("sky").Is("yellow")).Then(ItsAFact.That("ground").Is("soft")));

            var expected = new List <IEvaluatable>();

            expected.Add(If
                         .When(Any.Of(ItsAFact.That("sky").Is("blue"))
                               .Or(ItsAFact.That("sky").Is("red"))
                               .Or(ItsAFact.That("sky").Is("yellow"))
                               .IsTrue())
                         .Then(ItsAFact.That("ground").Is("soft")));
            // Act...
            var results = ImplicationHelper.MergeImplications(input);

            // Assert...
            CollectionAssert.AreEquivalent(expected, results);
        }
        private IEnumerable <IEvaluatable> GetCartesianImplicationsFromWorld <WorldType>(WorldType world)
        {
            var allFactsFromWorld = _worldAnalyser.GetAttributesAndValues(world).Select(attVal => ItsAFact.That(attVal.Key).Is(attVal.Value));
            var factPairs         = CreateCartesianPairs(allFactsFromWorld);
            var implications      = factPairs.Select(factPair => If.When(factPair.Item1).Then(factPair.Item2));

            return(implications);
        }