@Test public void testGetEqualOrGreater() { LongSkipList list = new LongSkipList(); list.add(0L); LongSkipList.SkipListNode node = list.getGreaterOrEqual(1L); Assert.assertNull(node); list.add(1L); list.add(2L); node = list.getGreaterOrEqual(3L); Assert.assertNull(node); list.add(3L); node = list.getGreaterOrEqual(4L); Assert.assertNull(node); node = list.getGreaterOrEqual(1L); assert node != null; Assert.assertEquals(1L, node.getKey()); node = list.getNext(node); assert node != null; Assert.assertEquals(2L, node.getKey()); node = list.getNext(node); assert node != null; Assert.assertEquals(3L, node.getKey()); node = list.getNext(node); Assert.assertNull(node); }
@Test public void testDeletingIteration() { final LongSkipList list = new LongSkipList(); for (int i = 0; i < 1000; i += 2) { list.add(i); list.add(i); } for (int i = 1; i < 1000; i += 2) { list.add(i); list.add(i); } Assert.assertEquals(2000, list.size()); LongSkipList.SkipListNode node = list.getMinimumNode(); for (long i = 0; i < 1000; i++) { assert node != null; Assert.assertEquals(i, node.getKey()); node = list.getNext(node); Assert.assertEquals(i, node.getKey()); node = list.getNext(node); } Assert.assertNull(node); node = list.getMaximumNode(); for (long i = 0; i < 1000; i++) { assert node != null; Assert.assertEquals(999 - i, node.getKey()); node = list.getPrevious(node); Assert.assertEquals(999 - i, node.getKey()); node = list.getPrevious(node); } Assert.assertNull(node); for (int i = 0; i < 1000; i++) { Assert.assertTrue(list.remove(i)); } Assert.assertEquals(1000, list.size()); node = list.getMinimumNode(); for (long i = 0; i < 1000; i++) { assert node != null; Assert.assertEquals(i, node.getKey()); node = list.getNext(node); } Assert.assertNull(node); node = list.getMaximumNode(); for (long i = 0; i < 1000; i++) { assert node != null; Assert.assertEquals(999L - i, node.getKey()); node = list.getPrevious(node); } Assert.assertNull(node); }
@Test public void testBackwardIteration() { final LongSkipList list = new LongSkipList(); for (int i = 0; i < 10000; ++i) { list.add(i); } long last = Long.MAX_VALUE; LongSkipList.SkipListNode node = list.getMaximumNode(); while (node != null) { long current = node.getKey(); Assert.assertTrue(current < last); last = current; node = list.getPrevious(node); } for (int i = 0; i < 10000; ++i) { node = list.getMaximumNode(); while (node != null) { node = list.getPrevious(node); } } }
@Test public void testForwardIteration() { final LongSkipList list = new LongSkipList(); for (int i = 0; i < 10000; ++i) { list.add(i); } long last = -1; LongSkipList.SkipListNode node = list.getMinimumNode(); while (node != null) { long current = node.getKey(); Assert.assertTrue(current > last); last = current; node = list.getNext(node); } for (int i = 0; i < 10000; ++i) { node = list.getMinimumNode(); while (node != null) { node = list.getNext(node); } } }