Beispiel #1
0
        public void AddNull()
        {
            var tree = new DuplicableSimpleBSTree <string, string>();

            Assert.Throws <System.ArgumentNullException>(() => tree.Add(null, "smt"));
            Assert.Throws <System.ArgumentNullException>(() => tree.Add("smt", null));
            Assert.Throws <System.ArgumentNullException>(() => tree.Add(null, null));
        }
Beispiel #2
0
        public void Depth()
        {
            var tree = new DuplicableSimpleBSTree <int, int>();

            tree.Add(4, 4);
            tree.Add(9, 9);
            tree.Add(10, 10);
            tree.Add(8, 8);
            tree.Add(1, 1);

            Assert.Equal(0, tree.Root.Depth);
            Assert.Equal(1, tree.Root.Left.Depth);
            Assert.Equal(1, tree.Root.Right.Depth);
            Assert.Equal(2, tree.Root.Right.Right.Depth);
            Assert.Equal(2, tree.Root.Right.Left.Depth);
        }
Beispiel #3
0
        public void TraversePostOrder()
        {
            var tree = new DuplicableSimpleBSTree <int, int>();

            tree.Add(4, 4);
            tree.Add(9, 9);
            tree.Add(10, 10);
            tree.Add(8, 8);
            tree.Add(1, 1);
            tree.Add(9, 9);
            tree.Add(3, 3);

            int[] correct = { 3, 1, 8, 10, 9, 9, 4 };
            int   i       = 0;

            foreach (var node in tree.PostOrderTraversal())
            {
                Assert.Equal(correct[i], node.Key);
                i++;
            }
        }
Beispiel #4
0
        public void TraverseBFS()
        {
            var tree = new DuplicableSimpleBSTree <int, int>();

            tree.Add(4, 4);
            tree.Add(9, 9);
            tree.Add(10, 10);
            tree.Add(8, 8);
            tree.Add(1, 1);
            tree.Add(10, 10);
            tree.Add(3, 3);

            int[] correct = { 4, 1, 9, 3, 8, 10, 10 };
            int   i       = 0;

            foreach (var node in tree.BFS())
            {
                Assert.Equal(correct[i], node.Value);
                i++;
            }
        }
Beispiel #5
0
        public void HeightEmpty()
        {
            var tree = new DuplicableSimpleBSTree <int, int>();

            Assert.Equal(0, tree.Height);
        }
Beispiel #6
0
        public void RemoveNullKey()
        {
            var tree = new DuplicableSimpleBSTree <string, string>();

            Assert.Throws <System.ArgumentNullException>(() => tree.Remove(null));
        }