Example #1
0
        public void Test_Add_Then_Verify_Properties()
        {
            //         30
            //        /  \
            //       20   40
            //      /      \
            //     10       50
            //    /        / \
            //   5      ->45  60
            //  /              \
            // 3               70
            //  \              /
            //   4            65
            IBinarySearchTree <byte> bt = this.CreateFullBinaryTree();

            bt.Add(45);

            BT.Node <byte>?node = bt.Get(45);

            Assert.False(bt.IsEmpty);
            Assert.NotNull(node);
            Assert.NotNull(node !.Parent);
            Assert.NotNull(node !.Parent !.Right);
            Assert.Equal(50, node.Parent !.Value);
            Assert.Null(node.Left);
            Assert.Null(node.Right);
        }
        public void Test_Add()
        {
            IBinarySearchTree <byte> bt = this.CreateInstance();

            bt.Add(10);

            Assert.True(bt.Contains(10));
        }
        public void Test_Add_When_New()
        {
            IBinarySearchTree <byte> bt = this.CreateInstance();

            bt.Add(100);

            Assert.True(bt.Contains(100));
            Assert.False(bt.IsEmpty);
        }
Example #4
0
        public void Test_Add_Then_Verify_Properties()
        {
            //     10                    10
            //    /   \                 /   \
            //   4     50              4     50
            //  / \   /  \      =>    / \   /  \
            // 3   5 30   65         3   5 30   70
            //      / \   / \       /     / \   / \
            //     20 40 60  70    2     20 40 65  70
            IBinarySearchTree <byte> bt = this.CreateFullBinaryTree();

            bt.Add(2);

            BT.Node <byte> node = bt.Get(2) !;

            Assert.False(bt.IsEmpty);
            Assert.NotNull(node.Parent);
            Assert.NotNull(node.Parent !.Left);
            Assert.Null(node.Left);
            Assert.Null(node.Right);
            Assert.Equal(3, node.Parent !.Value);
        }
        public void BSTWithLinkedList_Add_EmptyTree_AddToRoot()
        {
            // Arrange, Act
            _bst.Add(1);

            // Assert
            Assert.AreEqual(1, _bst.Count);
        }