Example #1
0
 public void Remove_Testing()
 {
     // removing a non-existing value should throw exceptions
     {
         IRedBlackTree <int> tree = RedBlackTreeLinked.New <int>();
         tree.Add(1);
         tree.Add(3);
         Assert.ThrowsException <ArgumentException>(() => tree.Remove(2));
     }
     // normal remove checking
     {
         IRedBlackTree <int> tree = RedBlackTreeLinked.New <int>();
         tree.Add(1);
         tree.Add(2);
         tree.Add(3);
         Assert.IsTrue(tree.Count is 3);
         tree.Remove(1);
         Assert.IsFalse(tree.Contains(1));
         Assert.IsTrue(tree.Count is 2);
         tree.Remove(2);
         Assert.IsFalse(tree.Contains(2));
         Assert.IsTrue(tree.Count is 1);
         tree.Remove(3);
         Assert.IsFalse(tree.Contains(3));
         Assert.IsTrue(tree.Count is 0);
     }
     {
         IRedBlackTree <int> tree = RedBlackTreeLinked.New <int>();
         Iterate(100, i => tree.Add(i));
         Assert.IsTrue(tree.Count is 100);
         Iterate(100, i => tree.Remove(i));
         Assert.IsTrue(tree.Count is 0);
     }
 }
Example #2
0
 public void TryRemove_Testing()
 {
     // removing a non-existing value should return false
     {
         IRedBlackTree <int> tree = RedBlackTreeLinked.New <int>();
         tree.Add(1);
         tree.Add(3);
         Assert.IsFalse(tree.TryRemove(2).Success);
     }
     // normal remove checking
     {
         IRedBlackTree <int> tree = RedBlackTreeLinked.New <int>();
         tree.Add(1);
         tree.Add(2);
         tree.Add(3);
         Assert.IsTrue(tree.Count is 3);
         Assert.IsTrue(tree.TryRemove(1).Success);
         Assert.IsFalse(tree.Contains(1));
         Assert.IsTrue(tree.Count is 2);
         Assert.IsTrue(tree.TryRemove(2).Success);
         Assert.IsFalse(tree.Contains(2));
         Assert.IsTrue(tree.Count is 1);
         Assert.IsTrue(tree.TryRemove(3).Success);
         Assert.IsFalse(tree.Contains(3));
         Assert.IsTrue(tree.Count is 0);
     }
     {
         IRedBlackTree <int> tree = RedBlackTreeLinked.New <int>();
         Iterate(100, i => tree.Add(i));
         Assert.IsTrue(tree.Count is 100);
         Iterate(100, i => tree.Remove(i));
         Assert.IsTrue(tree.Count is 0);
     }
 }