Пример #1
0
        public void MatchedHighestWeightReturnsProperWhenNonMatchesIsGreater()
        {
            var table = new RuleTable(1);

            var firstMatch = new List<Move> { Moves.Paper };
            table.SetMatched(firstMatch);
            var firstRules = table.FindRulesByAntecedents(firstMatch);
            Do(firstRules[0].IncrementWeight, 20);
            Do(firstRules[1].IncrementWeight, 10);

            var secondMatch = new List<Move> { Moves.Rock };
            table.SetMatched(secondMatch);
            var secondRules = table.FindRulesByAntecedents(secondMatch);
            Do(secondRules[0].IncrementWeight, 6);
            Do(secondRules[1].IncrementWeight, 5);

            var res = table.GetMatchedHighestWeight();
            Assert.Equal(6, res.Weight);
        }
Пример #2
0
        public void MatchedHighestWeightIsNullWhenNoMatches()
        {
            var table = new RuleTable(2);

            var res = table.GetMatchedHighestWeight();

            Assert.Null(res);
        }
Пример #3
0
        public void MatchedHighestWeightReturnsOneOfTopIfMoreThanOneWeightSame()
        {
            var table = new RuleTable(1);

            var firstMatch = new List<Move> { Moves.Paper };

            table.SetMatched(firstMatch);

            var rules = table.FindRulesByAntecedents(firstMatch);

            var rule1 = rules[0];
            var rule2 = rules[1];
            var rule3 = rules[2];

            rule1.IsMatched = true;
            Do(rule1.IncrementWeight, 10);

            rule2.IsMatched = true;
            Do(rule2.IncrementWeight, 10);

            rule3.IsMatched = true;
            Do(rule3.IncrementWeight, 9);

            var res = table.GetMatchedHighestWeight();

            Assert.Equal(10, res.Weight);
        }