public void AcceptVisitorExample()
        {
            var tree = new RedBlackTree<string, int> {{"cat", 1}, {"dog", 2}, {"canary", 3}};

            // There should be 3 items in the tree.
            Assert.AreEqual(3, tree.Count);

            // Create a visitor that will simply count the items in the tree.
            var visitor =
                new CountingVisitor<KeyValuePair<string, int>>();

            // Make the tree call IVisitor<T>.Visit on all items contained.
            tree.AcceptVisitor(visitor);

            // The counting visitor would have visited 3 items.
            Assert.AreEqual(3, visitor.Count);
        }
Exemple #2
0
        public void AcceptVisitorExample()
        {
            var tree = new RedBlackTree <string, int> {
                { "cat", 1 }, { "dog", 2 }, { "canary", 3 }
            };

            // There should be 3 items in the tree.
            Assert.AreEqual(3, tree.Count);

            // Create a visitor that will simply count the items in the tree.
            var visitor =
                new CountingVisitor <KeyValuePair <string, int> >();

            // Make the tree call IVisitor<T>.Visit on all items contained.
            tree.AcceptVisitor(visitor);

            // The counting visitor would have visited 3 items.
            Assert.AreEqual(3, visitor.Count);
        }
Exemple #3
0
        public void Simple()
        {
            var tree = new RedBlackTree<int, string>();

            for (var i = 0; i < 50; i++)
            {
                tree.Add(i, i.ToString());
            }

            var visitor = new KeyTrackingVisitor<int, string>();
            tree.AcceptVisitor(visitor);

            Assert.IsFalse(visitor.HasCompleted);

            Assert.AreEqual(visitor.TrackingList.Count, 50);

            var list = new List<int>(visitor.TrackingList);

            for (var i = 0; i < 50; i++)
            {
                Assert.IsTrue(list.Contains(i));
            }
        }
Exemple #4
0
        public void Simple()
        {
            var tree = new RedBlackTree <int, string>();

            for (var i = 0; i < 50; i++)
            {
                tree.Add(i, i.ToString());
            }

            var visitor = new KeyTrackingVisitor <int, string>();

            tree.AcceptVisitor(visitor);

            Assert.IsFalse(visitor.HasCompleted);

            Assert.AreEqual(visitor.TrackingList.Count, 50);

            var list = new List <int>(visitor.TrackingList);

            for (var i = 0; i < 50; i++)
            {
                Assert.IsTrue(list.Contains(i));
            }
        }