Пример #1
0
        public void Should_Check_PostOrder_Traversal()
        {
            //arrange
            var tree = new MyBinarySearchTree <int>();

            tree.Insert(38);
            tree.Insert(5);
            tree.Insert(45);
            tree.Insert(1);
            tree.Insert(9);
            tree.Insert(47);
            tree.Insert(8);
            tree.Insert(15);
            tree.Insert(46);
            tree.Insert(13);

            var postOrderTraversal = new int[] { 1, 8, 13, 15, 9, 5, 46, 47, 45, 38 };

            //act
            var result = tree.PostOrderTraversal().ToArray();

            //assert
            tree.Count.ShouldBeEquivalentTo(10);

            postOrderTraversal.Length.ShouldBeEquivalentTo(result.Length);
            for (int i = 0; i < postOrderTraversal.Length; i++)
            {
                postOrderTraversal[i].ShouldBeEquivalentTo(result[i]);
            }
        }
Пример #2
0
        public void Should_Check_PostOrder_Traversal_Empty()
        {
            //arrange
            var tree = new MyBinarySearchTree <int>();
            var postOrderTraversal = new int[] { };

            //act
            var result = tree.PostOrderTraversal().ToArray();

            //assert
            tree.Count.ShouldBeEquivalentTo(0);
            postOrderTraversal.Length.ShouldBeEquivalentTo(result.Length);
        }