public void Many_levels() { var sList = new Skiplist(); var size = 32; for (int i = 0; i < size; i += 2) { sList.Add(i); } for (int i = 1; i < size; i += 2) { sList.Add(i); } for (int i = 0; i < size; i++) { Assert.True(sList.Search(i)); } // removing every 3rd element for (int i = 0; i < size; i += 3) { Assert.True(sList.Erase(i)); } // make sure the remaining elements are there for (int i = 0; i < size; i++) { if (i % 3 == 0) { continue; } Assert.True(sList.Search(i)); } }
public void TwoLevels_Erase() { var list = new Skiplist(); list.Add(1); list.Add(2); list.Add(5); list.Add(7); //next add should trigger new level list.Add(10); list.Add(12); //add random order list.Add(9); list.Add(4); list.Add(19); list.Add(17); Assert.True(list.Erase(5)); Assert.False(list.Search(5)); Assert.True(list.Erase(1)); Assert.False(list.Search(1)); Assert.True(list.Search(10)); }
public void SkipList_Erases() { var list = new Skiplist <int>(4, 0.5); list.Add(1); list.Add(2); list.Add(1); list.Add(1); list.Add(1); list.Add(2); list.Add(3); // not in list Assert.False(list.Erase(4)); Assert.True(list.Erase(1)); Assert.True(list.Erase(2)); Assert.True(list.Erase(1)); Assert.True(list.Erase(1)); Assert.True(list.Erase(1)); Assert.True(list.Erase(2)); Assert.True(list.Erase(3)); // list should be empty Assert.False(list.Erase(1)); Assert.False(list.Erase(2)); Assert.False(list.Erase(3)); // not in list Assert.False(list.Erase(4)); }
public void OneLevel() { var list = new Skiplist(); list.Add(1); list.Add(5); list.Add(10); Assert.True(list.Search(1)); Assert.True(list.Search(5)); Assert.True(list.Search(10)); Assert.True(list.Erase(5)); Assert.False(list.Search(5)); list.Add(4); list.Add(4); Assert.True(list.Erase(4)); Assert.True(list.Search(4)); }
public void SkipListAddTest() { var skiplist = new Skiplist <int>(); skiplist.Add(5); skiplist.Add(50); var str = skiplist.ToString(); skiplist.Add(500); skiplist.Add(5000); skiplist.Add(51); skiplist.Add(501); Assert.AreEqual("0 5 50 51 500 501 5000 0 ", skiplist.ToString()); }
public void SkipList_Adds_Searches() { var list = new Skiplist <int>(4, 0.5); list.Add(1); list.Add(2); list.Add(1); list.Add(1); list.Add(2); list.Add(3); Assert.True(list.Search(1)); Assert.True(list.Search(2)); Assert.True(list.Search(3)); }
public void ThrowsOnDuplicateKey() { var list = new Skiplist<int, int>(KeyStrategy.Unique) {{1, 1}}; Assert.Throws<DuplicateKeyException>(() => list.Add(1, 2)); }