public void TernarySearchTree_Test()
        {
            var tree = new TernarySearchTree <char>();

            var testCount = 1000;

            var testStrings = new List <string>();

            while (testCount > 0)
            {
                var testString = randomString(3);
                testStrings.Add(testString);
                testCount--;
            }

            testStrings = new List <string>(testStrings.Distinct());

            foreach (var testString in testStrings)
            {
                tree.Insert(testString.ToArray());
            }

            //IEnumerable test
            Assert.AreEqual(tree.Count, tree.Count());

            foreach (var item in tree)
            {
                var existing = new string(item);
                Assert.IsTrue(testStrings.Contains(existing));
            }

            foreach (var item in testStrings)
            {
                Assert.IsTrue(tree.Contains(item.ToArray()));
            }

            foreach (var testString in testStrings)
            {
                tree.Delete(testString.ToArray());
            }
        }
        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 InsertTest3()
        {
            tree.Insert("cute", 1);
            tree.Insert("cup", 2);
            tree.Delete("cup");
            tree.Insert("cup", 3);

            Triplet[] expected = new Triplet[] {
                new Triplet('c', 0, false),

                null,
                new Triplet('u', 0, false),
                null,

                null,
                new Triplet('t', 0, false),
                null,

                new Triplet('p', 3, true),
                new Triplet('e', 1, true),
                null,
                null, null, null, null, null, null
            };
            CollectionAssertEx.AreEqual(expected, tree.BFS(x => new Triplet(x.Char, x.Value, x.IsEos)));
        }
        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());
        }