Ejemplo n.º 1
0
        public void GetKeysInOrder_NonEmptyTree_ReturnsCorrectAnswer()
        {
            var tree = new AATree <int>();

            tree.AddRange(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
            tree.GetKeysInOrder().SequenceEqual(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).Should().BeTrue();
        }
Ejemplo n.º 2
0
        public void AddRange_MultipleKeys_FormsCorrectTree()
        {
            var tree = new AATree <int>();

            tree.AddRange(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
            tree.Count.Should().Be(10);
            tree.GetKeysInOrder().SequenceEqual(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).Should().BeTrue();
            tree.GetKeysPostOrder().SequenceEqual(new[] { 1, 3, 2, 5, 7, 10, 9, 8, 6, 4 }).Should().BeTrue();
            Validate(tree.Root);
        }
Ejemplo n.º 3
0
        public void Constructor_UseCustomComparer_FormsCorrectTree()
        {
            var tree = new AATree <int>(Comparer <int> .Create((x, y) => y.CompareTo(x)));

            tree.AddRange(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
            tree.GetMax().Should().Be(1);
            tree.GetMin().Should().Be(10);
            tree.GetKeysInOrder().SequenceEqual(new[] { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }).Should().BeTrue();
            Validate(tree.Root);
        }
Ejemplo n.º 4
0
        public void GetKeysInOrder_NonEmptyTree_ReturnsCorrectAnswer()
        {
            var tree = new AATree <int>();

            tree.AddRange(new [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });

            var expected = new [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var actual   = tree.GetKeysInOrder();

            Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));
        }
Ejemplo n.º 5
0
        public void Add_MultipleKeys_FormsCorrectTree()
        {
            var tree = new AATree <int>();

            foreach (var elem in new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })
            {
                tree.Add(elem);
                tree.Count.Should().Be(elem);
                tree.Contains(elem).Should().BeTrue();
            }

            tree.GetKeysInOrder().SequenceEqual(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).Should().BeTrue();
            tree.GetKeysPostOrder().SequenceEqual(new[] { 1, 3, 2, 5, 7, 10, 9, 8, 6, 4 }).Should().BeTrue();
            Validate(tree.Root);
        }
Ejemplo n.º 6
0
        public void Constructor_UseCustomComparer_FormsCorrectTree()
        {
            var tree = new AATree <int>(Comparer <int> .Create((x, y) => y.CompareTo(x)));

            tree.AddRange(new [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
            Assert.AreEqual(1, tree.GetMax());
            Assert.AreEqual(10, tree.GetMin());

            var expected = new [] { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
            var actual   = tree.GetKeysInOrder();

            Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));

            Validate(tree.Root);
        }
Ejemplo n.º 7
0
        public void AddRange_MultipleKeys_FormsCorrectTree()
        {
            var tree = new AATree <int>();

            tree.AddRange(new [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });

            Assert.AreEqual(10, tree.Count);

            var expected = new [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var actual   = tree.GetKeysInOrder();

            Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));

            expected = new [] { 1, 3, 2, 5, 7, 10, 9, 8, 6, 4 };
            actual   = tree.GetKeysPostOrder();
            Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));

            Validate(tree.Root);
        }
Ejemplo n.º 8
0
        public void Add_MultipleKeys_FormsCorrectTree()
        {
            var tree = new AATree <int>();

            foreach (int elem in new [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })
            {
                tree.Add(elem);
                Assert.AreEqual(elem, tree.Count);
                Assert.IsTrue(tree.Contains(elem));
            }

            var expected = new [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var actual   = tree.GetKeysInOrder();

            Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));

            expected = new [] { 1, 3, 2, 5, 7, 10, 9, 8, 6, 4 };
            actual   = tree.GetKeysPostOrder();
            Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));

            Validate(tree.Root);
        }
Ejemplo n.º 9
0
        public void GetKeysInOrder_EmptyTree_ReturnsCorrectAnswer()
        {
            var tree = new AATree <int>();

            tree.GetKeysInOrder().ToList().Count.Should().Be(0);
        }
Ejemplo n.º 10
0
        public void GetKeysInOrder_EmptyTree_ReturnsCorrectAnswer()
        {
            var tree = new AATree <int>();

            Assert.IsTrue(tree.GetKeysInOrder().ToList().Count == 0);
        }