public void PrefixTree_CountMatchesNumberOfWordsInTree() { PrefixTree tree = new PrefixTree(); tree.Insert("CART"); tree.Insert("DINO"); tree.Insert("TAR"); tree.Insert("PEN"); Assert.AreEqual(4, tree.Count); }
public void GivenString_Put_ShoulGeneratePrefixTree() { var tree = new PrefixTree(new TrieTreeNode()); bool result = tree.Insert("apple"); Assert.IsTrue(result); }
public void PrefixTree_ExactMatchWorksWithWrongCase() { PrefixTree tree = new PrefixTree(); tree.Insert("PATRIK"); Assert.IsFalse(tree.IsExactMatch("pat")); Assert.IsTrue(tree.IsExactMatch("patrik")); }
public void PrefixTree_ExactMatch() { PrefixTree tree = new PrefixTree(); tree.Insert("PATRIK"); Assert.IsFalse(tree.IsExactMatch("PAT")); Assert.IsTrue(tree.IsExactMatch("PATRIK")); }
public void GivenValidInputString_StartWith_ShouldReturnTrue() { var tree = new PrefixTree(new TrieTreeNode()); tree.Insert("apple"); var result = tree.StartWith("app"); Assert.IsTrue(result); }
public void GivenValidInputStringButInvalidSearch_Search_ShouldReturnFalse() { var tree = new PrefixTree(new TrieTreeNode()); tree.Insert("apple"); var result = tree.Search("app"); Assert.IsFalse(result); }
public void GivenString_Get_ShouldReturnTrue() { var tree = new PrefixTree(new TrieTreeNode()); tree.Insert("apple"); var result = tree.Search("apple"); Assert.IsTrue(result); }
public void PrefixTree_PartialMatch() { PrefixTree tree = new PrefixTree(); tree.Insert("PATRIK"); Assert.IsTrue(tree.IsPartialMatch("P")); Assert.IsTrue(tree.IsPartialMatch("PAT")); Assert.IsFalse(tree.IsPartialMatch("PAD")); Assert.IsFalse(tree.IsPartialMatch("T")); Assert.IsFalse(tree.IsPartialMatch("")); }
public PrefixTree Build() { PrefixTree tree = new PrefixTree(); string[] lines = File.ReadAllLines(_file.FullName); foreach (string line in lines) { if (line.StartsWith("CUSTOM") || line.StartsWith("BASEWORDS") || line.StartsWith("DEFINITION")) { continue; } else if (line.StartsWith("COMPOUND")) { string[] parts = line.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2) { string[] words = parts[1].Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries); foreach (string word in words) { string temp = word.Trim(); tree.Insert(temp); } } } else { string[] parts = line.Split(new char[] { '>' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2) { string[] words = parts[1].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); foreach (string word in words) { tree.Insert(word); } } } } return tree; }
public void PrefixTree_WordsAreInsertedAsLowercase() { PrefixTree tree = new PrefixTree(); tree.Insert("CART"); tree.Insert("DINO"); tree.Insert("TAR"); tree.Insert("PEN"); Assert.IsNotNull(tree.Root.FindNode('c')); }
public void PrefixTree_PartialMatchWorksWithWrongCase() { PrefixTree tree = new PrefixTree(); tree.Insert("PATRIK"); Assert.IsTrue(tree.IsPartialMatch("p")); Assert.IsTrue(tree.IsPartialMatch("pat")); Assert.IsFalse(tree.IsPartialMatch("pad")); Assert.IsFalse(tree.IsPartialMatch("t")); }