Esempio n. 1
0
        public void Breadth_First_returns_tree_value_in_level_order()
        {
            // Arrange
            BinarySearchTree tree = new BinarySearchTree();

            tree.Add(6);
            tree.Add(2);
            tree.Add(7);
            tree.Add(3);
            tree.Add(10);
            tree.Add(1);
            tree.Add(9);
            tree.Add(20);

            //     ___6___
            //    /       \
            //   2         7
            //  / \         \
            // 1   3         10
            //              /  \
            //             9    20

            //Breadth_First list: 6, 2, 7, 1, 3, 10, 9, 20

            // Act
            IEnumerable <int> result = tree.Breadth_First();

            // Assert
            int[] expected = new int[] { 6, 2, 7, 1, 3, 10, 9, 20 };
            Assert.Equal(expected, result);
        }