public void TryAdd_Testing() { // adding duplicate values should return false { IAvlTree <int> tree = AvlTreeLinked.New <int>(); Assert.IsTrue(tree.TryAdd(1).Success); Assert.IsFalse(tree.TryAdd(1).Success); } // normal add checking { IAvlTree <int> tree = AvlTreeLinked.New <int>(); Assert.IsTrue(tree.TryAdd(1).Success); Assert.IsTrue(tree.TryAdd(2).Success); Assert.IsTrue(tree.TryAdd(3).Success); Assert.IsTrue(tree.Count is 3); Assert.IsTrue(tree.Contains(1)); Assert.IsTrue(tree.Contains(2)); Assert.IsTrue(tree.Contains(3)); } { IAvlTree <int> tree = AvlTreeLinked.New <int>(); Iterate(100, i => tree.TryAdd(i)); Assert.IsTrue(tree.Count is 100); Iterate(100, i => Assert.IsTrue(tree.Contains(i))); } }
public void GetEnumerable_Testing() { #pragma warning disable CA1829 // Use Length/Count property instead of Count() when available { IAvlTree <int> tree = AvlTreeLinked.New <int>(); Assert.IsTrue(tree.Count() is 0); } { IAvlTree <int> tree = AvlTreeLinked.New <int>(); Assert.IsTrue(tree.TryAdd(1).Success); Assert.IsTrue(tree.Count() is 1); Assert.IsTrue(tree.SequenceEqual(Ɐ(1))); } { IAvlTree <int> tree = AvlTreeLinked.New <int>(); Assert.IsTrue(tree.TryAdd(1).Success); Assert.IsTrue(tree.TryAdd(2).Success); Assert.IsTrue(tree.TryAdd(3).Success); Assert.IsTrue(tree.Count() is 3); Assert.IsTrue(tree.SequenceEqual(Ɐ(1, 2, 3))); } { IAvlTree <int> tree = AvlTreeLinked.New <int>(); Assert.IsTrue(tree.TryAdd(1).Success); Assert.IsTrue(tree.TryAdd(2).Success); Assert.IsTrue(tree.TryAdd(3).Success); Assert.IsTrue(tree.TryAdd(4).Success); Assert.IsTrue(tree.TryAdd(5).Success); Assert.IsTrue(tree.TryAdd(6).Success); Assert.IsTrue(tree.TryAdd(7).Success); Assert.IsTrue(tree.TryAdd(8).Success); Assert.IsTrue(tree.TryAdd(9).Success); Assert.IsTrue(tree.Count() is 9); Assert.IsTrue(tree.SequenceEqual(Ɐ(1, 2, 3, 4, 5, 6, 7, 8, 9))); } #pragma warning restore CA1829 // Use Length/Count property instead of Count() when available }