Esempio n. 1
0
        public void Test_Remove__Element_Has_More_Left_Children_Should_correctly_remove_FIRST_element()
        {
            //Given
            var tree = new BinaryTreeCollection <int>(3)
            {
                0,
                1,
                2,
                -11,
                -10,
                -9,
                -8,
                -7,
                -6,
                -5,
                -4,
                -3,
                -2,
                -1
            };

            //When
            tree.Remove(-3);
            //Then
            Assert.Equal(new[] { -11, -10, -9, -8, -7, -6, -5, -4, -2, -1, 0, 1, 2 }, tree.InOrderTraversal());
        }
Esempio n. 2
0
        public void Test_Remove_When_Element_Has_Children_Size_Is_Larger()
        {
            //Given
            var tree = new BinaryTreeCollection <int>(3)
            {
                12,
                11,
                13,
                5,
                6,
                7,
                8,
                9,
                10,
                2,
                3,
                4,
                0,
                1
            };

            //When
            tree.Remove(6);
            //Then
            Assert.Equal(new[] { 0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13 }, tree.InOrderTraversal());
        }
Esempio n. 3
0
        public void Test_RemoveMethod_Tree_Only_Has_Rootnode()
        {
            //Given
            var tree = new BinaryTreeCollection <int>()
            {
                4,
            };

            //When
            Assert.True(tree.Remove(4));
            //Then
            Assert.Empty(tree);
        }
Esempio n. 4
0
        public void Test_Remove_When_Node_IS_ROOT_And_Is_Not_Full()
        {
            //Given
            var tree = new BinaryTreeCollection <int>(5)
            {
                1,
            };

            //When
            tree.Remove(1);
            //Then
            Assert.Empty(tree);
        }
Esempio n. 5
0
        public void Test_RemoveChild_Method_Remove_LEAF_When_Tree_Has_3_Nodes()
        {
            //Given
            var tree = new BinaryTreeCollection <int>
            {
                2,
                1,
                3
            };

            //Then
            Assert.True(tree.Remove(3));
            Assert.Equal(new[] { 1, 2 }, tree.InOrderTraversal());
        }
Esempio n. 6
0
        public void Test_RemoveChild_When_NODE_is_ROOT_and_has_only_1_child()
        {
            //Given
            var tree = new BinaryTreeCollection <int>
            {
                2,
                3,
                4,
                5
            };

            //Then
            Assert.True(tree.Remove(2));
            Assert.Equal(new[] { 3, 4, 5 }, tree.InOrderTraversal());
        }
Esempio n. 7
0
        public void Test_RemoveChild_When_Node_Is_ROOT_And_Has_2_Children()
        {
            //Given
            var tree = new BinaryTreeCollection <int>
            {
                5,
                3,
                6,
            };

            //When
            tree.Remove(5);
            //Then
            Assert.Equal(new[] { 3, 6 }, tree.InOrderTraversal());
        }
Esempio n. 8
0
        public void Test_RemoveChild_When_Node_is_ROOT_and_has_Only_Left_Children()
        {
            //Given
            var tree = new BinaryTreeCollection <int>
            {
                2,
                1,
                0,
                -1
            };

            //Then
            Assert.True(tree.Remove(2));
            Assert.Equal(new[] { -1, 0, 1 }, tree.InOrderTraversal());
        }
Esempio n. 9
0
        public void Test_RemoveChild_When_Node_Has_Only_Left_Children()
        {
            //Given
            var tree = new BinaryTreeCollection <int>
            {
                6,
                4,
                2,
                1,
                3
            };

            //Then
            Assert.True(tree.Remove(4));
            Assert.Equal(new[] { 1, 2, 3, 6 }, tree.InOrderTraversal());
        }
Esempio n. 10
0
        public void Test_RemoveChild_Edge_Case()
        {
            //Given
            var tree = new BinaryTreeCollection <int>
            {
                -1,
                2,
                0,
                1,
                3
            };

            //When
            tree.Remove(2);
            //Then
            Assert.Equal(new[] { -1, 0, 1, 3 }, tree.InOrderTraversal());
        }
Esempio n. 11
0
        public void Test_RemoveChild_Method_Should_Return_TRUE_When_Removed_Node_Is_Left_Leaf()
        {
            //Given
            var node = new Node <int>(3);
            var tree = new BinaryTreeCollection <int>
            {
                5,
                2,
                6,
                1,
                node.FirstValue,
            };

            //Then
            Assert.True(tree.Remove(node.FirstValue));
            Assert.Equal(new[] { 1, 2, 5, 6 }, tree.InOrderTraversal());
        }
Esempio n. 12
0
        public void Test_RemoveChild_Method_Should_Work_Correctly_When_Node_Has_1_Child()
        {
            //Given
            var tree = new BinaryTreeCollection <int>
            {
                2,
                1,
                3,
                4,
                5,
                6
            };

            //Then
            Assert.True(tree.Remove(4));
            Assert.Equal(new[] { 1, 2, 3, 5, 6 }, tree.InOrderTraversal());
        }
Esempio n. 13
0
        public void Test_RemoveMethod_When_Node_Is_Root_Size_Is_2()
        {
            //Given
            var tree = new BinaryTreeCollection <int>(2)
            {
                4,
                5,
                2,
                3,
                6,
                7
            };

            //When
            Assert.True(tree.Remove(4));
            //Then
            Assert.Equal(new[] { 2, 3, 5, 6, 7 }, tree.InOrderTraversal());
        }
Esempio n. 14
0
        public void Test_Remove_Should_Correctly_Work_When_Element_Is_Leaf()
        {
            //Given
            var tree = new BinaryTreeCollection <int>()
            {
                3,
                5,
                6,
                7,
                8,
                9
            };

            //When
            tree.Remove(9);
            //Then
            Assert.Equal(new[] { 3, 5, 6, 7, 8 }, tree.InOrderTraversal());
        }
Esempio n. 15
0
        public void Test_Remove__Element_Is_Leaf_Should_correctly_remove_Middle_element()
        {
            //Given
            var tree = new BinaryTreeCollection <int>(3)
            {
                3,
                5,
                6,
                7,
                8,
                9
            };

            //When
            tree.Remove(8);
            //Then
            Assert.Equal(new[] { 3, 5, 6, 7, 9 }, tree.InOrderTraversal());
        }
Esempio n. 16
0
        public void Test_Remove__Element_Has_One_Right_Child_Should_correctly_remove_LAST_element()
        {
            //Given
            var tree = new BinaryTreeCollection <int>(2)
            {
                0,
                1,
                2,
                3,
                4,
                5,
            };

            //When
            tree.Remove(3);
            //Then
            Assert.Equal(new[] { 0, 1, 2, 4, 5 }, tree.InOrderTraversal());
        }
Esempio n. 17
0
        public void Test_RemoveChild_When_Node_Has_2_Children()
        {
            //Given
            var tree = new BinaryTreeCollection <int>
            {
                4,
                1,
                0,
                5,
                6,
                2
            };

            //When
            tree.Remove(1);
            //Then
            Assert.Equal(new[] { 0, 2, 4, 5, 6 }, tree.InOrderTraversal());
        }
Esempio n. 18
0
        public void Test_RemoveChild_Check_That_NO_Node_is_LOST_When_NodeToDelete_Is_ROOT()
        {
            //Given
            var tree = new BinaryTreeCollection <int>
            {
                4,
                1,
                5,
                6,
                0,
                2,
                3
            };

            //When
            tree.Remove(4);
            //Then
            Assert.Equal(new[] { 0, 1, 2, 3, 5, 6 }, tree.InOrderTraversal());
        }
Esempio n. 19
0
        public void Test_RemoveChild_Node_Has_2_Children_Another_Case()
        {
            //Given
            var tree = new BinaryTreeCollection <int>
            {
                5,
                3,
                6,
                2,
                4,
                0,
                1
            };

            //When
            tree.Remove(3);
            //Then
            Assert.Equal(new[] { 0, 1, 2, 4, 5, 6 }, tree.InOrderTraversal());
        }
Esempio n. 20
0
        public void Test_RemoveChild_another_edge_case()
        {
            //Given
            var tree = new BinaryTreeCollection <int>
            {
                5,
                3,
                6,
                0,
                4,
                7,
                4
            };

            //When
            tree.Remove(3);
            //Then
            Assert.Equal(new[] { 0, 4, 4, 5, 6, 7 }, tree.InOrderTraversal());
        }
Esempio n. 21
0
        public void Test_Remove_Node_Is_Leaf_Parent_should_have_SAME_CHILD()
        {
            //Given
            var tree = new BinaryTreeCollection <int>(3)
            {
                3,
                5,
                6,
                7,
                8,
                9
            };

            //When
            tree.Remove(9);
            Node <int> foundNode = tree.FindNode(5);

            //Then
            Assert.Equal(new[] { 7, 8 }, foundNode.Right);
        }
Esempio n. 22
0
        public void Test_Remove_Node_Is_Leaf_Check_That_Parent_Child_Is_Null()
        {
            //Given
            var tree = new BinaryTreeCollection <int>()
            {
                3,
                5,
                6,
                7,
                8,
                9
            };

            //When
            tree.Remove(9);
            Node <int> foundNode = tree.FindNode(8);

            //Then
            Assert.Null(foundNode.Right);
        }
Esempio n. 23
0
        public void Test_RemoveChild_Edge_Case_When_Node_IS_ROOT()
        {
            //Given
            var tree = new BinaryTreeCollection <int>
            {
                20,
                6,
                1,
                30,
                21,
                31,
                22,
                8,
            };

            //When
            tree.Remove(20);
            //Then
            Assert.Equal(new[] { 1, 6, 8, 21, 22, 30, 31 }, tree.InOrderTraversal());
        }
Esempio n. 24
0
        public void Test_Remove__Element_Is_Leaf_Should_Use_Empty_Spaces_At_Next_Addition()
        {
            //Given
            var tree = new BinaryTreeCollection <int>(3)
            {
                3,
                5,
                6,
                7,
                8,
                9
            };

            //When
            tree.Remove(8);
            tree.Add(8);
            Node <int> foundNode = tree.FindNode(8);

            //Then
            Assert.Equal(new[] { 7, 8, 9 }, foundNode);
        }
Esempio n. 25
0
        public void Test_RemoveChild_Check_That_NO_Node_is_LOST_during_Deletion_process()
        {
            //Given
            var tree = new BinaryTreeCollection <int>
            {
                4,
                0,
                5,
                -1,
                -2,
                2,
                1,
                3,
                6
            };

            //When
            tree.Remove(1);
            //Then
            Assert.Equal(new[] { -2, -1, 0, 2, 3, 4, 5, 6 }, tree.InOrderTraversal());
        }
Esempio n. 26
0
        public void Test_Remove_When_Node_Has_2_Children_Size_Is_2()
        {
            //Given
            var tree = new BinaryTreeCollection <int>(2)
            {
                0,
                1,
                10,
                11,
                4,
                5,
                6,
                7,
                2,
                3,
            };

            //When
            tree.Remove(4);
            //Then
            Assert.Equal(new[] { 0, 1, 2, 3, 5, 6, 7, 10, 11 }, tree.InOrderTraversal());
        }
Esempio n. 27
0
        public void Test_RemoveChild_Check_Edge_Case()
        {
            //Given
            var tree = new BinaryTreeCollection <int>
            {
                20,
                7,
                30,
                4,
                15,
                3,
                5,
                12,
                17,
                16,
                18
            };

            //When
            tree.Remove(15);
            //Then
            Assert.Equal(new[] { 3, 4, 5, 7, 12, 16, 17, 18, 20, 30 }, tree.InOrderTraversal());
        }
Esempio n. 28
0
        public void Test_Remove__Element_Has_More_Right_Children_Should_correctly_remove_MIDDLE_element()
        {
            //Given
            var tree = new BinaryTreeCollection <int>(3)
            {
                0,
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9,
                10,
                11
            };

            //When
            tree.Remove(4);
            //Then
            Assert.Equal(new[] { 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11 }, tree.InOrderTraversal());
        }