Skip to content

Commit 10c85e2

Browse files
add more tests
1 parent 10f9011 commit 10c85e2

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

Sprint-2/implement_skip_list/skip_list_test.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,51 @@ def test_general_usage(self):
2626

2727
self.assertEqual(sl.to_list(), [1, 2, 3, 4, 5, 10])
2828

29+
def test_duplicate_values(self):
30+
"""Test that duplicate values are handled correctly"""
31+
sl = SkipList()
32+
33+
# Insert duplicates
34+
sl.insert(5)
35+
sl.insert(2)
36+
sl.insert(5)
37+
sl.insert(2)
38+
sl.insert(5)
39+
40+
# All duplicates should be in the list and sorted
41+
self.assertEqual(sl.to_list(), [2, 2, 5, 5, 5])
42+
43+
# Check membership for duplicates
44+
self.assertIn(2, sl)
45+
self.assertIn(5, sl)
46+
47+
# Verify non-existent values
48+
self.assertNotIn(1, sl)
49+
self.assertNotIn(3, sl)
50+
self.assertNotIn(6, sl)
51+
52+
def test_large_random_inserts(self):
53+
"""Test with larger dataset and random insertion order"""
54+
sl = SkipList()
55+
56+
# Insert numbers in random order
57+
numbers = [7, 3, 9, 1, 8, 2, 6, 4, 10, 5]
58+
for num in numbers:
59+
sl.insert(num)
60+
61+
# Should be sorted regardless of insertion order
62+
self.assertEqual(sl.to_list(), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
63+
64+
# Verify all numbers are found
65+
for num in range(1, 11):
66+
self.assertIn(num, sl)
67+
68+
# Verify numbers outside range are not found
69+
self.assertNotIn(0, sl)
70+
self.assertNotIn(11, sl)
71+
self.assertNotIn(15, sl)
72+
73+
2974

3075
if __name__ == "__main__":
3176
unittest.main()

0 commit comments

Comments
 (0)