mirror of
https://github.com/jlengrand/Coding4Interviews.git
synced 2026-03-10 08:11:24 +00:00
find_next_idx behaviour checked. Seems to work as expected
This commit is contained in:
@@ -12,15 +12,37 @@ import unittest
|
||||
|
||||
class test_hash_map_neighbour_collision(unittest.TestCase):
|
||||
|
||||
def test_add(self):
|
||||
def test__find_free_idx(self):
|
||||
hm = HMNeighbourCollision()
|
||||
|
||||
hm.add("One", "Ibiza")
|
||||
key = "One"
|
||||
value = "Ibiza"
|
||||
|
||||
my_key = hm._hash(key)
|
||||
idx = hm._find_free_idx(my_key)
|
||||
self.assertEqual(my_key, idx)
|
||||
|
||||
hm.add(key, value)
|
||||
self.assertEqual(hm.size(), 1)
|
||||
|
||||
hm.add("One", "Ibiza2")
|
||||
# We move one up
|
||||
idx = hm._find_free_idx(my_key)
|
||||
self.assertEqual(my_key - 1, idx)
|
||||
|
||||
hm.add(key, "Ibiza2")
|
||||
self.assertEqual(hm.size(), 2)
|
||||
|
||||
# We move one down
|
||||
idx = hm._find_free_idx(my_key)
|
||||
self.assertEqual(my_key + 1, idx)
|
||||
|
||||
hm.add(key, "Ibiza3")
|
||||
self.assertEqual(hm.size(), 3)
|
||||
|
||||
# We move two up
|
||||
idx = hm._find_free_idx(my_key)
|
||||
self.assertEqual(my_key - 2, idx)
|
||||
|
||||
class test_hash_map_table_collision(unittest.TestCase):
|
||||
|
||||
def test_add(self):
|
||||
|
||||
Reference in New Issue
Block a user