Пример #1
0
        public void Analyze_WithAMissingTag_InlcudesTheTagInSuggestedTags()
        {
            var parser = new TagRulesParser();
            var rules  = parser.Parse(Resources.Animals);
            var engine = new TagRuleEngine(rules);

            var results = engine.Analyze(new[] { "cat" });

            Assert.Contains(results.SuggestedTags, t => t.Result == "tail");
        }
Пример #2
0
        public void Parse_GivenASimpleWellFormedRule_ReturnsTheExpectedRule(string @operator)
        {
            var parser = new TagRulesParser();

            var result = parser.Parse($"a {@operator} b").Single();

            Assert.Equal(new[] { "a" }, result.Left);
            Assert.Equal(new[] { "b" }, result.Right);
            Assert.Equal(TagRule.StringToOperatorLookup[@operator], result.Operator);
        }
Пример #3
0
        public void Analyze_WithARejecteSuggestedTag_DoesNotIncludeTheRejectedTagInSuggestedTags()
        {
            var parser = new TagRulesParser();
            var rules  = parser.Parse(Resources.Animals);
            var engine = new TagRuleEngine(rules);

            var results = engine.Analyze(new[] { "whale" }, new[] { "hair" });

            Assert.DoesNotContain(results.SuggestedTags, s => s.Result == "whiskers");
        }
Пример #4
0
        public void Analyze_WithAMissingTag_InlcudesTheTagInMissingTagSets()
        {
            var parser = new TagRulesParser();
            var rules  = parser.Parse(Resources.Animals);
            var engine = new TagRuleEngine(rules);

            var results = engine.Analyze(new[] { "cat" });

            Assert.Contains(results.MissingTagSets, s => s.Result.Contains("tail"));
        }
Пример #5
0
        public void Analyze_WithAMissingTag_DoesNotIncludesRootAbstractDescdendantTagsInSuggestedTags()
        {
            var parser = new TagRulesParser();
            var rules  = parser.Parse(Resources.Animals);
            var engine = new TagRuleEngine(rules);

            var results = engine.Analyze(new[] { "tail" });

            Assert.Contains(results.SuggestedTags, s => s.Result == "animal");
        }
Пример #6
0
        public void Analyze_WithARejectedMissingTag_DoesNotIncludeTheRejectedTagInMissingTagSets()
        {
            var parser = new TagRulesParser();
            var rules  = parser.Parse(Resources.Animals);
            var engine = new TagRuleEngine(rules);

            var results = engine.Analyze(new[] { "cat" }, new[] { "hair" });

            Assert.DoesNotContain(results.MissingTagSets, s => s.Result.Contains("hair"));
        }
Пример #7
0
        public void Analyze_WithARejectedExistingTag_IncludesTheExistingTagInTheExistingRejectedTags()
        {
            var parser = new TagRulesParser();
            var rules  = parser.Parse(Resources.Animals);
            var engine = new TagRuleEngine(rules);

            var results = engine.Analyze(new[] { "cat" }, new[] { "mammal" });

            Assert.Contains(results.ExistingRejectedTags, t => t == "cat");
        }
Пример #8
0
        public void Analyze_WithAnExcludedTag_DoesNotIncludeTheExcludedTagInSuggestedTags()
        {
            var parser = new TagRulesParser();
            var rules  = parser.Parse(Resources.Music);
            var engine = new TagRuleEngine(rules);

            var results = engine.Analyze(new[] { "rock", "instrumental" });

            Assert.DoesNotContain(results.SuggestedTags, s => s.Result == "vocals");
        }
Пример #9
0
        public void Analyze_WithAMoreSpecificImplication_IncludesBothTagsInMissingTagSets()
        {
            var parser = new TagRulesParser();
            var rules  = parser.Parse(Resources.Animals);
            var engine = new TagRuleEngine(rules);

            var results = engine.Analyze(new[] { "dog" });

            Assert.Contains(results.MissingTagSets, s => s.Result.Contains("hair"));
            Assert.Contains(results.MissingTagSets, s => s.Result.Contains("fur"));
        }
Пример #10
0
        public void Analyze_WithAMissingTag_InlcudesTheFirstConcreteTagInSuggestedTags()
        {
            var parser = new TagRulesParser();
            var rules  = parser.Parse(Resources.Animals);
            var engine = new TagRuleEngine(rules);

            var results = engine.Analyze(new[] { "tail" });

            Assert.Contains(results.SuggestedTags, s => s.Result == "mammal");
            Assert.DoesNotContain(results.SuggestedTags, s => s.Result == "cat");
        }
Пример #11
0
        public void Analyze_WithAFullyDescribedScenario_DoesNotSuggestExtraTags()
        {
            var parser = new TagRulesParser();
            var rules  = parser.Parse(Resources.Animals);
            var engine = new TagRuleEngine(rules);

            var results = engine.Analyze(new[] { "cat", "tail", "fur", "whiskers" });

            Assert.Empty(results.MissingTagSets);
            Assert.Empty(results.SuggestedTags);
        }
Пример #12
0
        public void Analyze_WithATagAlias_ReplacesTheAliasWithTheCanonicalTagInEffectiveTags()
        {
            var parser = new TagRulesParser();
            var rules  = parser.Parse(Resources.Animals);
            var engine = new TagRuleEngine(rules);

            var results = engine.Analyze(new[] { "feline" });

            Assert.Contains(results.EffectiveTags, t => t == "cat");
            Assert.DoesNotContain(results.EffectiveTags, t => t == "feline");
        }
Пример #13
0
        public void Analyze_WithAMoreSpecificSuggestion_IncludesBothTagsInSuggestedTags()
        {
            var parser = new TagRulesParser();
            var rules  = parser.Parse(Resources.Animals);
            var engine = new TagRuleEngine(rules);

            var results = engine.Analyze(new[] { "whale" });

            Assert.Contains(results.SuggestedTags, s => s.Result == "hair");
            Assert.Contains(results.SuggestedTags, s => s.Result == "whiskers");
        }
Пример #14
0
        public void Analyze_WithADescendantTag_InlcudesAncestorsOfTheTagInEffectiveTags()
        {
            var parser = new TagRulesParser();
            var rules  = parser.Parse(Resources.Animals);
            var engine = new TagRuleEngine(rules);

            var results = engine.Analyze(new[] { "cat" });

            Assert.Contains(results.EffectiveTags, t => t == "mammal");
            Assert.Contains(results.EffectiveTags, t => t == "animal");
            Assert.Contains(results.EffectiveTags, t => t == "object");
        }
Пример #15
0
        public void Parse_GivenACompositeRule_ReturnsTheExpectedRules()
        {
            var parser = new TagRulesParser();

            var results = parser.Parse("a :: b [c]");

            var specialization = results.Single(r => r.Operator == TagOperator.Specialization);
            var properties     = results.Single(r => r.Operator == TagOperator.Property);

            Assert.Equal(new[] { "a" }, specialization.Left);
            Assert.Equal(new[] { "b" }, specialization.Right);
            Assert.Equal(new[] { "a" }, properties.Left);
            Assert.Equal(new[] { "c" }, properties.Right);
        }
Пример #16
0
        public void Parse_GivenATagOfAKnowValidity_ParsesOrFailsToParseAsExpected(bool valid, string tag)
        {
            var parser = new TagRulesParser();

            void test()
            {
                var result = parser.Parse($"{tag} [ok]").Single();

                Assert.Equal(tag, result.Left.Single());
            }

            if (valid)
            {
                test();
            }
            else
            {
                Assert.ThrowsAny <Exception>(test);
            }
        }