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); }
public void testInsertBalanced_caseForWordIsNull() { const string word = null; Assert.Throws <ArgumentException>(() => hybridTrie.InsertBalanced(word)); }