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"); }
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); }
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"); }
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")); }
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"); }
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")); }
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"); }
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"); }
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")); }
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"); }
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); }
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"); }
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"); }
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"); }
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); }
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); } }