예제 #1
0
        static void Opgave3()
        {
            System.Console.WriteLine("\n=====   Opgave 3 : BinaryTree   =====\n");

            IBinaryTree <int>    intTree;
            IBinaryTree <string> stringTree;

            // Empty tree
            intTree = DSBuilder.CreateBinaryTreeEmpty();
            System.Console.WriteLine(intTree.Size());
            System.Console.WriteLine(intTree.Height());
            System.Console.WriteLine(intTree.ToPrefixString());
            System.Console.WriteLine(intTree.ToInfixString());
            System.Console.WriteLine(intTree.ToPostfixString());

            // Int tree
            intTree = DSBuilder.CreateBinaryTreeInt();
            System.Console.WriteLine(intTree.Size());
            System.Console.WriteLine(intTree.Height());
            System.Console.WriteLine(intTree.ToPrefixString());
            System.Console.WriteLine(intTree.ToInfixString());
            System.Console.WriteLine(intTree.ToPostfixString());
            System.Console.WriteLine(intTree.NumberOfNodesWithOneChild());

            // String tree
            stringTree = DSBuilder.CreateBinaryTreeString();
            System.Console.WriteLine(stringTree.Size());
            System.Console.WriteLine(stringTree.Height());
            System.Console.WriteLine(stringTree.ToPrefixString());
            System.Console.WriteLine(stringTree.ToInfixString());
            System.Console.WriteLine(stringTree.ToPostfixString());
        }
예제 #2
0
        static void Opgave4()
        {
            System.Console.WriteLine("\n=====   Opgave 4 : NumberOfNodes   =====\n");

            IBinaryTree <int>    intTree;
            IBinaryTree <string> stringTree;

            // Empty tree
            intTree = DSBuilder.CreateBinaryTreeEmpty();
            System.Console.WriteLine(intTree.NumberOfLeaves());
            System.Console.WriteLine(intTree.NumberOfNodesWithOneChild());
            System.Console.WriteLine(intTree.NumberOfNodesWithTwoChildren());

            // Int tree
            intTree = DSBuilder.CreateBinaryTreeInt();
            System.Console.WriteLine(intTree.NumberOfLeaves());
            System.Console.WriteLine(intTree.NumberOfNodesWithOneChild());
            System.Console.WriteLine(intTree.NumberOfNodesWithTwoChildren());

            // String tree
            stringTree = DSBuilder.CreateBinaryTreeString();
            System.Console.WriteLine(stringTree.NumberOfLeaves());
            System.Console.WriteLine(stringTree.NumberOfNodesWithOneChild());
            System.Console.WriteLine(stringTree.NumberOfNodesWithTwoChildren());
        }
        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);
        }
        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);
        }
        public void BinaryTree_08_NumberOfLeaves_3_OnStringTree()
        {
            // Arrange
            IBinaryTree <string> tree = DSBuilder.CreateBinaryTreeString();
            int expected = 4;

            // Act
            int actual = tree.NumberOfLeaves();

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void BinaryTree_10_NumberOfNodesWithTwoChildren_3_OnStringTree()
        {
            // Arrange
            IBinaryTree <string> tree = DSBuilder.CreateBinaryTreeString();
            int expected = 3;

            // Act
            int actual = tree.NumberOfNodesWithTwoChildren();

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void BinaryTree_07_ToPostfixString_3_OnStringTree()
        {
            // Arrange
            IBinaryTree <string> tree = DSBuilder.CreateBinaryTreeString();
            string expected           = "[ [ [ NIL NIL q ] [ NIL NIL g ] w ] [ [ NIL NIL o ] [ NIL NIL p ] a ] t ]";

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

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void BinaryTree_06_ToInfixString_3_OnStringTree()
        {
            // Arrange
            IBinaryTree <string> tree = DSBuilder.CreateBinaryTreeString();
            string expected           = "[ [ [ NIL q NIL ] w [ NIL g NIL ] ] t [ [ NIL o NIL ] a [ NIL p NIL ] ] ]";

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

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void BinaryTree_05_ToPrefixString_3_OnStringTree()
        {
            // Arrange
            IBinaryTree <string> tree = DSBuilder.CreateBinaryTreeString();
            string expected           = "[ t [ w [ q NIL NIL ] [ g NIL NIL ] ] [ a [ o NIL NIL ] [ p NIL NIL ] ] ]";

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

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void BinaryTree_04_IsEmpty_3_OnStringTree()
        {
            // Arrange
            IBinaryTree <string> tree = DSBuilder.CreateBinaryTreeString();
            bool expected             = false;

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

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void BinaryTree_03_Height_3_OnStringTree()
        {
            // Arrange
            IBinaryTree <string> tree = DSBuilder.CreateBinaryTreeString();
            int expected = 2;

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

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