Example #1
0
  public void testDeletion() throws Exception {
    List skipList = new SkipList();

    Random random = new Random();
    Collection<Integer> numbers = new LinkedList<Integer>();
    for (int i = 0; i < 100; i++) {
      int x = random.nextInt(1000); // insertion
      while (numbers.contains(x)) {
        x = random.nextInt(1000);
      }
      numbers.add(x);
      skipList.insert(x);
    }
    for (Integer integer : numbers) {
      SkipNode skipNode = skipList.findElement(integer);
      Assert.assertNotNull("Failed for " + integer, skipNode);

      skipList.remove(integer);
      skipNode = skipList.findElement(integer);
      Assert.assertNull("Failed for " + integer, skipNode);
    }
  }
Example #2
0
  public void testInsertion() throws Exception {
    List skipList = new SkipList();

    Random random = new Random();
    Collection<Integer> numbers = new LinkedList<Integer>();
    for (int i = 0; i < 5; i++) {
      int x = random.nextInt(100); // insertion
      numbers.add(x);
      skipList.insert(x);
    }
    for (Integer integer : numbers) {
      SkipNode skipNode = skipList.findElement(integer);
      Assert.assertNotNull("Failed for " + integer, skipNode);
      Integer found = (Integer) skipNode.getElement();
      Assert.assertEquals(integer, found);
    }
  }