public void AppliesTo_TermOccursInRange_ReturnsTrue() { IKeyTerm term = KeyTermMatchBuilderTests.AddMockedKeyTerm("tom", 002003002); KeyTermMatch match = new KeyTermMatch(new List <Word>(new Word[] { "tom" }), term, true); Assert.IsTrue(match.AppliesTo(002003002, 002003002)); Assert.IsTrue(match.AppliesTo(002003002, 002003003)); Assert.IsTrue(match.AppliesTo(002003001, 002003002)); Assert.IsTrue(match.AppliesTo(002003001, 002003003)); }
public void AppliesTo_TermAllowedToMatchAnywhere_ReturnsTrue() { IKeyTerm term = KeyTermMatchBuilderTests.AddMockedKeyTerm("tom"); KeyTermMatch match = new KeyTermMatch(new List <Word>(new Word[] { "tom" }), term, false); Assert.IsTrue(match.AppliesTo(-1, -1)); }
public void RuleToLimitMatchToTermRefs() { Dictionary <string, KeyTermRule> rules = new Dictionary <string, KeyTermRule>(); KeyTermRule rule = new KeyTermRule(); rule.id = "ask"; rule.Rule = KeyTermRule.RuleType.MatchForRefOnly; rules[rule.id] = rule; KeyTermMatchBuilder bldr = new KeyTermMatchBuilder(AddMockedKeyTerm(rule.id, 34), new ReadonlyDictionary <string, KeyTermRule>(rules), null); Assert.AreEqual(1, bldr.Matches.Count()); KeyTermMatch ktm = VerifyKeyTermMatch(bldr, 0, false, "ask"); Assert.IsFalse(ktm.AppliesTo(30, 33)); Assert.IsTrue(ktm.AppliesTo(34, 34)); Assert.IsFalse(ktm.AppliesTo(35, 39)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Verifies the key term match. /// </summary> /// ------------------------------------------------------------------------------------ private static KeyTermMatch VerifyKeyTermMatch(KeyTermMatchBuilder bldr, int iMatch, bool matchAnywhere, params string[] words) { KeyTermMatch ktm = bldr.Matches.ElementAt(iMatch); Assert.AreEqual(words.Length, ktm.WordCount); for (int i = 0; i < words.Length; i++) { Assert.AreEqual(words[i], ktm[i].Text); } Assert.IsTrue(ktm.MatchForRefOnly != matchAnywhere); // The following is really a test of the KeyTermMatch.AppliesTo method: if (matchAnywhere) { Random r = new Random(DateTime.Now.Millisecond); Assert.IsTrue(ktm.AppliesTo(r.Next(), r.Next())); } return(ktm); }