public void PreorderTraversalTest(int[] arrInput, string arrOutput)
        {
            //PreorderTraversalTest(int input, int[] arrInput, int[] arrOutput)
            //var res = PreorderTraversal.run(input, arrInput);
            string result = string.Empty;

            PreorderTraversal.StartOrder(arrInput, ref result);

            Assert.AreEqual(result.Trim(), arrOutput);
        }
Пример #2
0
        public void TestPreOrderTraversal()
        {
            TreeNode <int>   root       = new TreeNode <int>(1);
            ITraversal <int> _traversal = new PreorderTraversal <int>();

            root.Left        = new TreeNode <int>(2);
            root.Right       = new TreeNode <int>(3);
            root.Right.Right = new TreeNode <int>(5);
            root.Right.Left  = new TreeNode <int>(4);
            IList <int> expectedOutput = new List <int>(new List <int> {
                1, 2, 3, 4, 5
            });
            var binarytree = new BinaryTree <int>(root, _traversal);
            var output     = binarytree.Traverse();

            CollectionAssert.Equals(expectedOutput, output);
        }