Example #1
0
        public void BinarySearchTree_01_Insert_07_After13UnorderedInserts_ToInfixStringCorrect()
        {
            // Arrange
            IBinarySearchTree <int> tree = DSBuilder.CreateBinarySearchTreeIntEmpty();
            string expected = "[ [ NIL 3 [ [ NIL 7 NIL ] 8 [ NIL 12 NIL ] ] ] 17 [ [ NIL 24 NIL ] 26 [ NIL 32 [ [ NIL 34 [ [ NIL 37 NIL ] 42 NIL ] ] 45 [ NIL 50 NIL ] ] ] ] ]";


            // Act
            tree.Insert(17);
            tree.Insert(3);
            tree.Insert(26);
            tree.Insert(8);
            tree.Insert(24);
            tree.Insert(32);
            tree.Insert(7);
            tree.Insert(12);
            tree.Insert(45);
            tree.Insert(34);
            tree.Insert(50);
            tree.Insert(42);
            tree.Insert(37);
            string actual = tree.ToInfixString();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #2
0
        public void BinarySearchTree_03_RemoveMin_01_OnEmptyTree()
        {
            // Arrange
            IBinarySearchTree <int> tree = DSBuilder.CreateBinarySearchTreeIntEmpty();

            // Act & Assert
            Assert.Throws(typeof(BinarySearchTreeEmptyException), () => tree.RemoveMin());
        }
Example #3
0
        public void BinarySearchTree_04_Remove_01_OnEmptyTree()
        {
            // Arrange
            IBinarySearchTree <int> tree = DSBuilder.CreateBinarySearchTreeIntEmpty();


            // Act & Assert
            Assert.Throws(typeof(BinarySearchTreeElementNotFoundException), () => tree.Remove(1));
        }
Example #4
0
        public void BinarySearchTree_05_ToString_01_OnEmptyTree()
        {
            // Arrange
            IBinarySearchTree <int> tree = DSBuilder.CreateBinarySearchTreeIntEmpty();
            string expected = "";

            // Act
            string actual = tree.ToString();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #5
0
        public void BinarySearchTree_01_Insert_03_After1Insert_HeightEquals0()
        {
            // Arrange
            IBinarySearchTree <int> tree = DSBuilder.CreateBinarySearchTreeIntEmpty();
            int expected = 0;

            // Act
            tree.Insert(3);
            int actual = tree.Height();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #6
0
        public void BinarySearchTree_01_Insert_02_After1Insert_SizeEquals1()
        {
            // Arrange
            IBinarySearchTree <int> tree = DSBuilder.CreateBinarySearchTreeIntEmpty();
            int expected = 1;

            // Act
            tree.Insert(3);
            int actual = tree.Size();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #7
0
        public void BinarySearchTree_01_Insert_01_After1Insert_IsEmptyReturnsFalse()
        {
            // Arrange
            IBinarySearchTree <int> tree = DSBuilder.CreateBinarySearchTreeIntEmpty();
            bool expected = false;

            // Act
            tree.Insert(3);
            bool actual = tree.IsEmpty();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #8
0
        public void BinarySearchTree_01_Insert_06_After3UnorderedInserts_ToInfixStringCorrect()
        {
            // Arrange
            IBinarySearchTree <int> tree = DSBuilder.CreateBinarySearchTreeIntEmpty();
            string expected = "[ [ NIL 1 NIL ] 2 [ NIL 3 NIL ] ]";

            // Act
            tree.Insert(2);
            tree.Insert(1);
            tree.Insert(3);
            string actual = tree.ToInfixString();

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