示例#1
0
        public void AddTest2()
        {
            // Arrange
            Node node = new Node();

            // Declare and populate the nodes
            Node nodeA = new Node()
            {
                Value = "A"
            };
            Node nodeB = new Node()
            {
                Value = "B"
            };
            Node nodeC = new Node()
            {
                Value = "C"
            };

            // Instantiate the tree
            MyTree tree = new MyTree(nodeA);


            // Link the tree
            nodeA.Children.Add(nodeB);
            nodeA.Children.Add(nodeC);

            // Act
            tree.AddNode(nodeA, "Z");


            // Assert
            Assert.Equal("ABCZ", tree.BreadthFirst(nodeA));
        }
示例#2
0
        public void AddTest3()
        {
            // Arrange
            Node   node = new Node();
            MyTree tree = new MyTree(node);

            // Act

            tree.AddNode(node, "Y");

            // Assert
            Assert.Equal("Y", tree.BreadthFirst(node));
        }
示例#3
0
        public void Constructor_CreateTreeWithPreDefindeRootAndCreateEmptyTreeAndThenAddRoot_BothRootMustBeEqual()
        {
            //arrange
            MyTree <int> tree1;
            MyTree <int> tree2;
            int          value = 5;

            //act
            tree1 = new MyTree <int>(value);
            tree2 = new MyTree <int>();
            tree2.AddNode(value);
            //assert
            Assert.Equal(tree1.RootNode, tree2.RootNode);
        }
示例#4
0
        public void AddNode_AddNodeInt5BigerThenRoot4_CreateRightChildInt5ToRootNodeInt4()
        {
            //arrange
            MyTree <int> tree;
            int          expected = 5;
            int          actual;

            //act
            tree = new MyTree <int>(4);
            tree.AddNode(expected);
            actual = tree.RootNode.RightNode.Value;
            //assert
            Assert.Equal(expected, actual);
        }
示例#5
0
        public void AddNode_AddNodeInt3LessThenRoot4_CreateLeftChildInt3ToRootNodeInt4()
        {
            //arrange
            MyTree <int> tree;
            int          expected = 3;
            int          actual;

            //act
            tree = new MyTree <int>(4);
            tree.AddNode(expected);
            actual = tree.RootNode.LeftNode.Value;
            //assert
            Assert.Equal(expected, actual);
        }
示例#6
0
        public void DeleteNode_DeleteNodeInt4_TreeShoudNotContainInt4()
        {
            //arrange
            MyTree <int> tree = new MyTree <int>(10);

            tree.AddNode(11);
            tree.AddNode(7);
            tree.AddNode(6);
            tree.AddNode(4);
            tree.AddNode(3);
            tree.AddNode(2);
            tree.AddNode(5);
            MyNode <int> actual;

            //act
            tree.DeleteNode(4);
            actual = tree.FindNode(4);
            //assert
            Assert.Null(actual);
        }
示例#7
0
        public void GetMax_GetMaxElement11OfTree_Return11()
        {
            //arrange
            MyTree <int> tree = new MyTree <int>(10);

            tree.AddNode(5);
            tree.AddNode(11);
            tree.AddNode(7);
            tree.AddNode(6);
            tree.AddNode(4);
            tree.AddNode(2);
            int expected = 11;
            int actual;

            //act
            actual = tree.GetMax(tree.RootNode).Value;
            //assert
            Assert.Equal(expected, actual);
        }
示例#8
0
        public void FindNode_FindNotInt5_ReturnInt5()
        {
            //arrange
            MyTree <int> tree = new MyTree <int>(10);

            tree.AddNode(11);
            tree.AddNode(7);
            tree.AddNode(6);
            tree.AddNode(4);
            tree.AddNode(2);
            tree.AddNode(5);
            int expected = 5;
            int actual;

            //act
            actual = tree.FindNode(expected).Value;
            //assert
            Assert.Equal(expected, actual);
        }
示例#9
0
        public void AddTest1()
        {
            // Arrange
            Node node = new Node();

            // Declare and populate the nodes
            Node nodeA = new Node()
            {
                Value = "A"
            };
            Node nodeB = new Node()
            {
                Value = "B"
            };
            Node nodeC = new Node()
            {
                Value = "C"
            };
            Node nodeD = new Node()
            {
                Value = "D"
            };
            Node nodeE = new Node()
            {
                Value = "E"
            };
            Node nodeF = new Node()
            {
                Value = "F"
            };
            Node nodeG = new Node()
            {
                Value = "G"
            };
            Node nodeH = new Node()
            {
                Value = "H"
            };
            Node nodeI = new Node()
            {
                Value = "I"
            };
            Node nodeJ = new Node()
            {
                Value = "J"
            };
            Node nodeK = new Node()
            {
                Value = "K"
            };
            Node nodeL = new Node()
            {
                Value = "L"
            };
            Node nodeM = new Node()
            {
                Value = "M"
            };
            Node nodeN = new Node()
            {
                Value = "N"
            };
            Node nodeO = new Node()
            {
                Value = "O"
            };
            Node nodeP = new Node()
            {
                Value = "P"
            };
            Node nodeQ = new Node()
            {
                Value = "Q"
            };


            // Instantiate the tree
            MyTree tree = new MyTree(nodeA);

            // Link the tree.
            nodeA.Children.Add(nodeB);
            nodeA.Children.Add(nodeC);
            nodeA.Children.Add(nodeD);
            nodeA.Children.Add(nodeE);
            nodeA.Children.Add(nodeF);
            nodeA.Children.Add(nodeG);


            nodeB.Children.Add(nodeH);
            nodeB.Children.Add(nodeI);
            nodeB.Children.Add(nodeJ);


            nodeE.Children.Add(nodeK);
            nodeE.Children.Add(nodeL);

            nodeG.Children.Add(nodeM);

            nodeH.Children.Add(nodeN);
            nodeH.Children.Add(nodeO);

            nodeK.Children.Add(nodeP);

            nodeL.Children.Add(nodeQ);

            // Act
            tree.AddNode(nodeA, "Z");

            // Assert

            Assert.Equal("ABCDEFGZHIJKLMNOPQ", tree.BreadthFirst(nodeA));
        }
示例#10
0
        static void Main(string[] args)
        {
            MyArray <int> newArr = new MyArray <int>(10, -5);

            for (int i = 0; i < newArr.Length; i++)
            {
                newArr[i - 5] = i;
            }
            foreach (var item in newArr)
            {
                Debug.WriteLine(item);
            }
            Debug.WriteLine(newArr[-5]);


            Action <string>  SPrint = x => Console.WriteLine(x);
            Action <Student> Print  = x => SPrint(x.ToString());

            MyTree <Student> studTree = new MyTree <Student>();

            studTree.ElementAddEvent += StudTree_ElementAddEvent;

            studTree.AddNode(new Student("Name1", "SecondName1", 50));
            studTree.AddNode(new Student("Name2", "SecondName2", 25));
            studTree.AddNode(new Student("Name3", "SecondName3", 75));
            studTree.AddNode(new Student("Name4", "SecondName4", 50));
            studTree.AddNode(new Student("Name5", "SecondName5", 50));
            studTree.AddNode(new Student("Name6", "SecondName6", 15));
            studTree.AddNode(new Student("Name7", "SecondName7", 35));
            studTree.AddNode(new Student("Name8", "SecondName8", 99));
            studTree.AddNode(new Student("Name9", "SecondName9", 5));
            studTree.AddNode(new Student("Name9", "SecondName9", 65));
            studTree.AddNode(new Student("Name9", "SecondName9", 5));

            studTree.DeleteNode(new Student("Name9", "SecondName9", 5));

            SPrint("InorderPrint");
            studTree.InorderPrint(studTree.RootNode, Print);

            SPrint("PreorderedPrint");
            studTree.PreorderPrint(studTree.RootNode, Print);

            SPrint("\nforeach print");
            foreach (var item in studTree)
            {
                SPrint(item.ToString());
            }

            SPrint("\nConverted to list");
            var studList = studTree.ToList();

            foreach (var item in studList)
            {
                SPrint(item.ToString());
            }
            Console.ReadLine();
        }