Esempio n. 1
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());
        }
Esempio n. 2
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());
        }
Esempio n. 3
0
        public void BinaryTree_01_GetRoot_1_OnEmptyTree()
        {
            // Arrange
            IBinaryTree <int> tree = DSBuilder.CreateBinaryTreeEmpty();

            // Act & Assert
            Assert.Throws(typeof(BinarySearchTreeEmptyException), () => tree.GetRoot());
        }
        public void BinaryTree_02_Size_1_OnEmptyTree()
        {
            // Arrange
            IBinaryTree <int> tree = DSBuilder.CreateBinaryTreeEmpty();
            int expected           = 0;

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

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void BinaryTree_10_NumberOfNodesWithTwoChildren_1_OnEmptyTree()
        {
            // Arrange
            IBinaryTree <int> tree = DSBuilder.CreateBinaryTreeEmpty();
            int expected           = 0;

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

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void BinaryTree_08_NumberOfLeaves_1_OnEmptyTree()
        {
            // Arrange
            IBinaryTree <int> tree = DSBuilder.CreateBinaryTreeEmpty();
            int expected           = 0;

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

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void BinaryTree_07_ToPostfixString_1_OnEmptyTree()
        {
            // Arrange
            IBinaryTree <int> tree     = DSBuilder.CreateBinaryTreeEmpty();
            string            expected = "NIL";

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

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void BinaryTree_04_IsEmpty_1_OnEmptyTree()
        {
            // Arrange
            IBinaryTree <int> tree = DSBuilder.CreateBinaryTreeEmpty();
            bool expected          = true;

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

            // Assert
            Assert.AreEqual(expected, actual);
        }
        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);
        }
        public void BinaryTree_03_Height_1_OnEmptyTree()
        {
            // Arrange
            IBinaryTree <int> tree = DSBuilder.CreateBinaryTreeEmpty();
            int expected           = -1;

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

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