public void TernarySearchTree_Smoke_Test() { var searchTree = new TernarySearchTree <char>(); searchTree.Insert("cat".ToCharArray()); searchTree.Insert("cats".ToCharArray()); searchTree.Insert("cut".ToCharArray()); searchTree.Insert("cuts".ToCharArray()); searchTree.Insert("up".ToCharArray()); searchTree.Insert("bug".ToCharArray()); searchTree.Insert("bugs".ToCharArray()); Assert.IsTrue(searchTree.Contains("cat".ToCharArray())); Assert.IsTrue(searchTree.Contains("cut".ToCharArray())); Assert.IsFalse(searchTree.Contains("bu".ToCharArray())); searchTree.Delete("cuts".ToCharArray()); Assert.IsFalse(searchTree.Contains("cuts".ToCharArray())); var matches = searchTree.StartsWith("u".ToCharArray()); Assert.IsTrue(matches.Count == 1); matches = searchTree.StartsWith("cu".ToCharArray()); Assert.IsTrue(matches.Count == 1); matches = searchTree.StartsWith("bu".ToCharArray()); Assert.IsTrue(matches.Count == 2); matches = searchTree.StartsWith("c".ToCharArray()); Assert.IsTrue(matches.Count == 3); matches = searchTree.StartsWith("ca".ToCharArray()); Assert.IsTrue(matches.Count == 2); searchTree.Delete("cats".ToCharArray()); searchTree.Delete("up".ToCharArray()); searchTree.Delete("bug".ToCharArray()); searchTree.Delete("bugs".ToCharArray()); searchTree.Delete("cat".ToCharArray()); searchTree.Delete("cut".ToCharArray()); }
public void TernarySearchTree_Smoke_Test() { var tree = new TernarySearchTree <char>(); tree.Insert("cat".ToCharArray()); //IEnumerable test Assert.AreEqual(tree.Count, tree.Count()); tree.Insert("cats".ToCharArray()); //IEnumerable test Assert.AreEqual(tree.Count, tree.Count()); tree.Insert("cut".ToCharArray()); //IEnumerable test Assert.AreEqual(tree.Count, tree.Count()); tree.Insert("cuts".ToCharArray()); //IEnumerable test Assert.AreEqual(tree.Count, tree.Count()); tree.Insert("up".ToCharArray()); //IEnumerable test Assert.AreEqual(tree.Count, tree.Count()); tree.Insert("bug".ToCharArray()); //IEnumerable test Assert.AreEqual(tree.Count, tree.Count()); tree.Insert("bugs".ToCharArray()); //IEnumerable test Assert.AreEqual(tree.Count, tree.Count()); //IEnumerable test Assert.AreEqual(tree.Count, tree.Count()); Assert.IsTrue(tree.Contains("cat".ToCharArray())); Assert.IsTrue(tree.Contains("cut".ToCharArray())); Assert.IsFalse(tree.Contains("bu".ToCharArray())); Assert.IsTrue(tree.ContainsPrefix("bu".ToCharArray())); tree.Delete("cuts".ToCharArray()); Assert.IsFalse(tree.Contains("cuts".ToCharArray())); var matches = tree.StartsWith("u".ToCharArray()); Assert.IsTrue(matches.Count == 1); //IEnumerable test Assert.AreEqual(tree.Count, tree.Count()); matches = tree.StartsWith("cu".ToCharArray()); Assert.IsTrue(matches.Count == 1); matches = tree.StartsWith("bu".ToCharArray()); Assert.IsTrue(matches.Count == 2); matches = tree.StartsWith("c".ToCharArray()); Assert.IsTrue(matches.Count == 3); matches = tree.StartsWith("ca".ToCharArray()); Assert.IsTrue(matches.Count == 2); tree.Delete("cats".ToCharArray()); //IEnumerable test Assert.AreEqual(tree.Count, tree.Count()); tree.Delete("up".ToCharArray()); //IEnumerable test Assert.AreEqual(tree.Count, tree.Count()); tree.Delete("bug".ToCharArray()); //IEnumerable test Assert.AreEqual(tree.Count, tree.Count()); tree.Delete("bugs".ToCharArray()); //IEnumerable test Assert.AreEqual(tree.Count, tree.Count()); tree.Delete("cat".ToCharArray()); //IEnumerable test Assert.AreEqual(tree.Count, tree.Count()); tree.Delete("cut".ToCharArray()); //IEnumerable test Assert.AreEqual(tree.Count, tree.Count()); }