Beispiel #1
0
        public void TreadedTreeTraverse()
        {
            String[] input = "The quick brown fox jumped over the lazy brown dog's back".Split(' ');
            List <Tuple <int, String> > output = InitOutput();

            ThreadedTree threadedTree = new ThreadedTree();

            foreach (var i in input)
            {
                threadedTree.Insert(new Item(i));
            }
            threadedTree.Traverse();

            for (int i = 0; i < threadedTree.Report.Count; i++)
            {
                Assert.IsTrue(threadedTree.Report[i].Count == output[i].Item1);
                Assert.IsTrue(threadedTree.Report[i].Item.Value == output[i].Item2);
            }
        }
Beispiel #2
0
        public void ThreadedTreeInsert()
        {
            ThreadedTree threadedTree = new ThreadedTree();

            threadedTree.Insert(new Item("The"));
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Left == null);
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right == null);

            threadedTree.Insert(new Item("quick"));
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Left == null);
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right != null);
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).RightThread == false);
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Item.Value == "quick");

            threadedTree.Insert(new Item("brown"));
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Left != null);
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Right == null);
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Left.RightThread == true);
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Left.Right.Item.Value == "quick");
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Left.Item.Value == "brown");

            threadedTree.Insert(new Item("fox"));
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Left.Left != null);
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Left.Right != null);
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Left.Left.RightThread == true);
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Left.Left.Right.Item.Value == "brown");
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Left.Left.Item.Value == "fox");

            threadedTree.Insert(new Item("dog's"));
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Left.Right != null);
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Left.Right != null);
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Left.Right.RightThread == true);
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Left.Right.Right != null);
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Left.Right.Right.Item.Value == "quick");
            Assert.IsTrue(((ThreadedNode)threadedTree.Root).Right.Left.Right.Item.Value == "dog's");
        }