public void runNominalTestRemove_afterAddingWords() { // Set up before starting removing words IHybridTrie hybridTrie = new HybridTrie(); hybridTrie.Insert(wordsList); hybridTrie.Insert("l"); hybridTrie.Print("original"); // Run tests after adding words Assert.That(hybridTrie.Remove("lourd"), Is.False); Assert.That(hybridTrie.Remove("lourdss"), Is.False); TestRemove(hybridTrie, "luxe", hybridTrie.GetNullPointerCount() - 6, hybridTrie.GetHeight() - 0); TestRemove(hybridTrie, "leve", hybridTrie.GetNullPointerCount() - 4, hybridTrie.GetHeight() - 0); TestRemove(hybridTrie, "les", hybridTrie.GetNullPointerCount() - 2, hybridTrie.GetHeight() - 0); TestRemove(hybridTrie, "lou", hybridTrie.GetNullPointerCount() - 0, hybridTrie.GetHeight() - 0); TestRemove(hybridTrie, "lourds", hybridTrie.GetNullPointerCount() - 6, hybridTrie.GetHeight() - 0); TestRemove(hybridTrie, "loups", hybridTrie.GetNullPointerCount() - 8, hybridTrie.GetHeight() - 0); TestRemove(hybridTrie, "le", hybridTrie.GetNullPointerCount() - 2, hybridTrie.GetHeight() - 0); TestRemove(hybridTrie, "l", hybridTrie.GetNullPointerCount() - 2, hybridTrie.GetHeight() - 1); TestRemove(hybridTrie, "olive", hybridTrie.GetNullPointerCount() - 10, hybridTrie.GetHeight() - 1); TestRemove(hybridTrie, "tapis", hybridTrie.GetNullPointerCount() - 10, hybridTrie.GetHeight() - 0); TestRemove(hybridTrie, "vert", hybridTrie.GetNullPointerCount() - 8, hybridTrie.GetHeight() - 1); TestRemove(hybridTrie, "dans", hybridTrie.GetNullPointerCount() - 6, hybridTrie.GetHeight() - 2); TestRemove(hybridTrie, "de", hybridTrie.GetNullPointerCount() - 5, hybridTrie.GetHeight() - 1); }
protected void SetUp() { wordsList = new TextFileReader(EXAMPLE_PATH).WordsListe; hybridTrie = new HybridTrie(); hybridTrie.Insert(wordsList); }
public void testInsertWordsFromList() { HybridTrie hybridTrie = new HybridTrie(); hybridTrie.Insert(wordsList); const int expectedHybridTrieSize = 12; int calculatedHybridTrieSize = hybridTrie.GetWordCount(); Assert.AreEqual(calculatedHybridTrieSize, expectedHybridTrieSize); }
public void testRemoveAll() { HybridTrie hybridTrie = new HybridTrie(); hybridTrie.Insert("word1"); hybridTrie.Insert("word2"); hybridTrie.Insert("word3"); hybridTrie.RemoveAll(); Assert.That(hybridTrie.IsEmpty(), Is.True); }
public void testInsertWordsOneByOne() { HybridTrie hybridTrie = new HybridTrie(); hybridTrie.Insert("lou"); hybridTrie.Insert("leve"); hybridTrie.Insert("les"); hybridTrie.Insert("loups"); hybridTrie.Insert("dans"); hybridTrie.Insert("le"); hybridTrie.Insert("lourds"); const int expectedHybridTrieSize = 7; int calculatedHybridTrieSize = hybridTrie.GetWordCount(); Assert.AreEqual(calculatedHybridTrieSize, expectedHybridTrieSize); }
public void testInsertBalanced() { /* The purpose of this manipulation is to make an unbalanced tries by inserting a few words in order. */ TextFileReader textFileReader = new TextFileReader("triesalgav/files/Shakespeare/john.txt"); List <string> wordsListFromFile = new List <string>(); List <string> sortedList = new List <string>(); List <string> ordinaryList = new List <string>(); wordsListFromFile = textFileReader.WordsListe; // Split the original list to two other lists. for (int wordIndex = 0; wordIndex < wordsListFromFile.Count; wordIndex++) { if (wordIndex % 500 == 0) { sortedList.Add(wordsListFromFile[wordIndex]); } else { ordinaryList.Add(wordsListFromFile[wordIndex]); } } // Sort the first list in an ascending order and keep the second one as it is. sortedList.Sort(); // Insert both lists in each trie HybridTrie hybridTrie = new HybridTrie(); hybridTrie.Insert(sortedList); hybridTrie.Insert(ordinaryList); HybridTrie balancedHybridTrie = new HybridTrie(); balancedHybridTrie.InsertBalanced(sortedList); balancedHybridTrie.InsertBalanced(ordinaryList); // insertBalanced() method should guarantee a better average depth i.e. a balanced trie. Assert.That(balancedHybridTrie.GetAverageDepthOfLeaves() < hybridTrie.GetAverageDepthOfLeaves(), Is.True); }