コード例 #1
0
        public void GetRulesForWorlds_GivenWorlds_ExpectRuleSetfor2Worlds()
        {
            // Arrange...
            var jsonWorlds = new List <string>();

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

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

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

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

            // Assert...
            CollectionAssert.AreEquivalent(expected, results);
        }
コード例 #2
0
        public void CreateRule_GivenWorlds_ExpectSimpleImply()
        {
            // Arrange...
            var world1 = "{'Name':'Bob', 'Age':'40'}";

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

            expected.Add(If
                         .When(ItsAFact.That("Name").Is("Bob"))
                         .Then(ItsAFact.That("Age").Is("40"))
                         );
            expected.Add(If
                         .When(ItsAFact.That("Age").Is("40"))
                         .Then(ItsAFact.That("Name").Is("Bob"))
                         );

            // Act...
            var results = sut.GetRulesForWorlds(new List <string>()
            {
                world1
            }, InferenceMethod.Optimistic);

            // Assert...
            Assert.AreEqual(expected, results);
        }
コード例 #3
0
 private IEnumerable <IEvaluatable> GetRulesFromWorlds <WorldType>(IEnumerable <WorldType> dymeWorlds, InferenceType inferenceType)
 {
     switch (inferenceType)
     {
     case InferenceType.Pessimistic:
         return(_inferenceEngineSvc.GetRulesForWorlds(dymeWorlds, InferenceMethod.Pessimistic));
     }
     throw new Exception("Invalid inference type");
 }
コード例 #4
0
        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);
        }
コード例 #5
0
        public void PessimisticWorld_GivenWorlds_ExpectMetrics()
        {
            // 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'}");
            jsonWorlds.Add("{'Name':'Joe', 'Age':'40', 'Year': '2040'}");
            var sut    = new DymeInferenceEvaluator(_worldReader, _worldAnalyser, _metricSvc);
            var expect = new Dictionary <string, int>();

            expect.Add("EvaluateProposition", 498);
            expect.Add("GetValueFromWorld", 498);
            // Act...
            var rules   = sut.GetRulesForWorlds(jsonWorlds, InferenceMethod.Pessimistic);
            var results = (_metricSvc as DefaultMetricService).metrics;

            // Assert...
            CollectionAssert.AreEquivalent(expect, results);
        }