Exemplo n.º 1
0
        public void Add_KeyAlreadyInTree_ThrowsException()
        {
            var tree = new AaTree <int>();

            tree.AddRange(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
            Assert.Throws <ArgumentException>(() => tree.Add(1));
        }
Exemplo n.º 2
0
 static void Main(string[] args)
 {
     var tree = new AaTree<int, string>();
     Console.WriteLine("The AA tree created.");
     var nums = new[] { -5, 20, 14, 11, 8, -3, 111, 7, 100, -55 };
     for (int i = 0; i < nums.Length; i++)
     {
         tree.Add(nums[i], "value");
     }
 }
Exemplo n.º 3
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);
        }