Esempio n. 1
0
        public void CanGetMatchedConsequent()
        {
            var table = new RuleTable(2);

            var rules = table.Rules;

            table.SetMatched(new List<Move>() { Moves.Paper, Moves.Rock });

            var rule = table.GetMatchedConsequent(Moves.Scissors);

            Assert.NotNull(rule);
            Assert.True(rule.IsMatched);
            Assert.Equal(Moves.Paper, rule.Antecedents[0]);
            Assert.Equal(Moves.Rock, rule.Antecedents[1]);
            Assert.Equal(rule.Consequent, Moves.Scissors);
        }
Esempio n. 2
0
        public void CanSetMatched()
        {
            var table = new RuleTable(2);

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

            table.SetMatched(firstMatch);

            var rules = table.Rules;

            rules.Where(r => r.Antecedents.SequenceEqual(firstMatch)).ToList().ForEach(r => Assert.True(r.IsMatched));
            rules.Where(r => !r.Antecedents.SequenceEqual(firstMatch)).ToList().ForEach(r => Assert.False(r.IsMatched));

            var secondMatch = new List<Move> { Moves.Rock, Moves.Paper };

            table.SetMatched(secondMatch);
            rules.Where(r => r.Antecedents.SequenceEqual(secondMatch)).ToList().ForEach(r => Assert.True(r.IsMatched));
            rules.Where(r => !r.Antecedents.SequenceEqual(secondMatch)).ToList().ForEach(r => Assert.False(r.IsMatched));
        }
Esempio n. 3
0
        public void CanGetMatched()
        {
            var table = new RuleTable(2);

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

            table.SetMatched(firstMatch);

            var rules = table.FindRulesByAntecedents(firstMatch);

            var matched = table.GetMatched().ToList();

            Assert.Equal(5, matched.Count);
            Assert.Equal(rules[0], matched[0]);
            Assert.Equal(rules[1], matched[1]);
            Assert.Equal(rules[2], matched[2]);
            Assert.Equal(rules[3], matched[3]);
            Assert.Equal(rules[4], matched[4]);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }