@Test
  public void testIterator() {
    RedBlackTree<Integer> tree = new RedBlackTree<Integer>();
    for (int j = 0; j < 100; j++) {
      tree.insert(j);
    }
    Iterator<Integer> i = tree.iterator();
    try {
      i.remove();
      Assert.fail();
    } catch (NoSuchElementException e) {

    }
    Assert.assertTrue(i.hasNext());
    int test = 0;
    for (; i.hasNext();) {
      Integer val = i.next();
      Assert.assertEquals(Integer.valueOf(test++), val);
      if ((val & 1) == 0) {
        i.remove();
      }
    }
    try {
      i.next();
      Assert.fail();
    } catch (NoSuchElementException e) {

    }
    i = tree.iterator();
    for (int j = 1; j < 100; j += 2) {
      Assert.assertEquals(Integer.valueOf(j), i.next());
      i.remove();
    }
    try {
      i.remove();
      Assert.fail();
    } catch (NoSuchElementException e) {

    }
    Assert.assertTrue(tree.isEmpty());
  }