public void BasicEnumeratorTests() { CPStringTrie <string> .Enumerator e, e0; CPStringTrie <string> emptyTrie = new CPStringTrie <string>(); Assert.IsNotNull(emptyTrie.FindAtLeast("")); Assert.That(!emptyTrie.FindAtLeast("foo").IsValid); Assert.IsNull(emptyTrie.FindExact("")); Assert.That(!emptyTrie.Find("?", out e) && e != null && !e.IsValid); CPStringTrie <string> trie = new CPStringTrie <string>(); foreach (string key in BasicTestStrings()) { trie.Add(key, key); } Assert.That(trie.Find("An", out e)); Assert.That(!trie.Find("Am", out e0)); Assert.AreEqual(e0.CurrentKey, e.CurrentValue); Assert.That(e.MovePrev()); Assert.AreEqual("A", e.CurrentKey); Assert.AreEqual("A", e.CurrentValue); Assert.AreEqual("An", e0.CurrentKey); Assert.That(e0.MoveNext()); Assert.AreEqual("Ant", e0.CurrentKey); Assert.That(!trie.Find("2Noté", out e)); Assert.AreEqual("2Noté thé Ŭnicodé.", e.CurrentKey); Assert.IsNull(trie.FindExact("2Noté")); Assert.IsNotNull(trie.FindExact("2An")); Assert.AreEqual("16single", trie.FindAtLeast("16simgle").CurrentKey); Assert.That(!trie.Find("32zzz", out e)); Assert.AreEqual("4", e.CurrentKey); Assert.That(e.MoveNext()); Assert.AreEqual("4 ", e.CurrentKey); Assert.That(e.MovePrev()); Assert.AreEqual("4", e.CurrentKey); Assert.That(e.MovePrev()); Assert.AreEqual("32z", e.CurrentKey); Assert.That(!trie.Find("zzz", out e)); Assert.That(!e.IsValid); Assert.That(e.MovePrev()); Assert.AreEqual("z", e.CurrentValue); TestFind(trie, 500); }
public void BasicTests() { CPStringTrie <string> trie = new CPStringTrie <string>(); int count = 0; List <string> testStrings = new List <string>(BasicTestStrings()); // Test insertion foreach (string key in testStrings) { trie.Add(key, key); Assert.AreEqual(++count, trie.Count); } Assert.That(trie.Contains(new KeyValuePair <string, string>("a", "a"))); Assert.That(!trie.Contains(new KeyValuePair <string, string>("a", ""))); // Test forward enumeration count = 0; string last = null; foreach (KeyValuePair <string, string> p in trie) { Assert.That(p.Key == p.Value); Assert.That(last == null || string.Compare(last, p.Value, StringComparison.Ordinal) < 0); last = p.Value; count++; } Assert.AreEqual(count, trie.Count); // Test deletion Debug.Assert(testStrings.Count % 16 == 0); for (int i = 0; i < testStrings.Count; i++) { // Remove keys in a different order than they were added string key = testStrings[i ^ 0xF]; Assert.That(trie.Contains(new KeyValuePair <string, string>(key, key))); Assert.That(trie[key] == key); trie[key] = "!"; Assert.That(trie[key] == "!"); Assert.That(trie.Remove(key)); Assert.That(!trie.ContainsKey(key)); } Assert.AreEqual(0, trie.Count); }