Пример #1
0
        /// <summary>
        /// Constructor for the iterator
        /// </summary>
        /// <param name="tree">Tree to iterate</param>
        public InOrderTraversal(IBinaryTree <T> tree)
        {
            _root = tree.GetRoot();
            _next = tree.GetRoot();

            if (_next == null)
            {
                return;
            }

            // Go far left
            while (_next.LeftNode != null)
            {
                _next = _next.LeftNode;
            }
        }
Пример #2
0
        public void BinaryTree_01_GetRoot_1_OnEmptyTree()
        {
            // Arrange
            IBinaryTree <int> tree = DSBuilder.CreateBinaryTreeEmpty();

            // Act & Assert
            Assert.Throws(typeof(BinarySearchTreeEmptyException), () => tree.GetRoot());
        }
Пример #3
0
        public void BinaryTree_03_MakeEmpty_GetRootIsNullAfterMakeEmpty()
        {
            // Arrange
            IBinaryTree <int> tree = DSBuilder.CreateBinaryTreeInt();

            // Act
            tree.MakeEmpty();

            // Assert
            Assert.Throws(typeof(BinarySearchTreeEmptyException), () => tree.GetRoot());
        }
Пример #4
0
        public void BinaryTree_01_GetRoot_1_OnEmptyTree()
        {
            // Arrange
            IBinaryTree <int> tree     = DSBuilder.CreateBinaryTreeEmpty();
            BinaryNode <int>  expected = null;

            // Act
            BinaryNode <int> actual = tree.GetRoot();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #5
0
        public void BinaryTree_01_GetRoot_3_OnStringTree_2_DataCorrect()
        {
            // Arrange
            IBinaryTree <string> tree = DSBuilder.CreateBinaryTreeString();
            string expected           = "t";

            // Act
            string actual = tree.GetRoot().data;

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #6
0
        public void BinaryTree_01_GetRoot_3_OnStringTree_1_NotNull()
        {
            // Arrange
            IBinaryTree <string> tree         = DSBuilder.CreateBinaryTreeString();
            BinaryNode <string>  not_expected = null;

            // Act
            BinaryNode <string> actual = tree.GetRoot();

            // Assert
            Assert.AreNotEqual(not_expected, actual);
        }
Пример #7
0
        public void BinaryTree_01_GetRoot_2_OnIntTree_2_DataCorrect()
        {
            // Arrange
            IBinaryTree <int> tree = DSBuilder.CreateBinaryTreeInt();
            int expected           = 5;

            // Act
            int actual = tree.GetRoot().data;

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #8
0
        public void BinaryTree_01_GetRoot_2_OnIntTree_1_NotNull()
        {
            // Arrange
            IBinaryTree <int> tree         = DSBuilder.CreateBinaryTreeInt();
            BinaryNode <int>  not_expected = null;

            // Act
            BinaryNode <int> actual = tree.GetRoot();

            // Assert
            Assert.AreNotEqual(not_expected, actual);
        }
Пример #9
0
        public void BinaryTree_03_MakeEmpty_GetRootIsNullAfterMakeEmpty()
        {
            // Arrange
            IBinaryTree <int> tree     = DSBuilder.CreateBinaryTreeInt();
            BinaryNode <int>  expected = null;

            // Act
            tree.MakeEmpty();
            BinaryNode <int> actual = tree.GetRoot();

            // Assert
            Assert.AreEqual(expected, actual);
        }