コード例 #1
0
        public void BinaryTree_IntDefaultComparer_ExpetedResult()
        {
            int[]            array = { 27, 35, 14, 19, 10, 42, 31 };
            BinaryTree <int> tree  = new BinaryTree <int>();

            tree.AddElements(array);

            int[] expected = { 10, 14, 19, 27, 31, 35, 42 };

            int[] actual = new int[array.Length];
            int   i      = 0;

            foreach (int value in tree.InorderTraversal())
            {
                actual[i++] = value;
            }

            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
        public void BinaryTree_StringCustomComparer_ExpetedResult()
        {
            string[]             array = { "aaa", "a", "aa", "aaaa", "aaaaa" };
            StringCustomComparer comp  = new StringCustomComparer();
            BinaryTree <string>  tree  = new BinaryTree <string>(comp.Compare);

            tree.AddElements(array);

            string[] expected = { "a", "aa", "aaa", "aaaa", "aaaaa" };

            string[] actual = new string[array.Length];
            int      i      = 0;

            foreach (string value in tree.InorderTraversal())
            {
                actual[i++] = value;
            }

            Assert.AreEqual(expected, actual);
        }
コード例 #3
0
        public void BinaryTree_CustomTypeDefaultComparer_ExpetedResult()
        {
            Book b1 = new Book()
            {
                price = 322, author = "K", name = "M", year = 1998
            };
            Book b2 = new Book()
            {
                price = 200, author = "K", name = "M", year = 1990
            };
            Book b3 = new Book()
            {
                price = 144, author = "K", name = "D", year = 1900
            };
            Book b4 = new Book()
            {
                price = 400, author = "K", name = "M", year = 1999
            };

            Book[] books = { b1, b2, b3, b4 };

            BinaryTree <Book> tree = new BinaryTree <Book>();

            tree.AddElements(books);

            Book[] expected = { b3, b2, b1, b4 };

            Book[] actual = new Book[books.Length];
            int    i      = 0;

            foreach (Book b in tree.InorderTraversal())
            {
                actual[i++] = b;
            }

            Assert.AreEqual(expected, actual);
        }