def test_auto_resizing(self): ht = HashTable(1) hash_table_insert(ht, 'first', 'test') self.assertEqual(ht.capacity, 2) hash_table_insert(ht, 'second', 'test2') self.assertEqual(ht.capacity, 4) hash_table_insert(ht, 'third', 'test3') self.assertEqual(ht.capacity, 8) hash_table_remove(ht, 'third') hash_table_remove(ht, "second") self.assertEqual(ht.capacity, 4)
def test_hash_table_removes_correctly(self): ht = HashTable(8) hash_table_insert(ht, "key-0", "val-0") hash_table_insert(ht, "key-1", "val-1") hash_table_insert(ht, "key-2", "val-2") hash_table_insert(ht, "key-3", "val-3") hash_table_insert(ht, "key-4", "val-4") hash_table_insert(ht, "key-5", "val-5") hash_table_insert(ht, "key-6", "val-6") hash_table_insert(ht, "key-7", "val-7") hash_table_insert(ht, "key-8", "val-8") hash_table_insert(ht, "key-9", "val-9") hash_table_remove(ht, "key-9") hash_table_remove(ht, "key-8") hash_table_remove(ht, "key-7") hash_table_remove(ht, "key-6") hash_table_remove(ht, "key-5") hash_table_remove(ht, "key-4") hash_table_remove(ht, "key-3") hash_table_remove(ht, "key-2") hash_table_remove(ht, "key-1") hash_table_remove(ht, "key-0") return_value = hash_table_retrieve(ht, "key-0") self.assertTrue(return_value is None) return_value = hash_table_retrieve(ht, "key-1") self.assertTrue(return_value is None) return_value = hash_table_retrieve(ht, "key-2") self.assertTrue(return_value is None) return_value = hash_table_retrieve(ht, "key-3") self.assertTrue(return_value is None) return_value = hash_table_retrieve(ht, "key-4") self.assertTrue(return_value is None) return_value = hash_table_retrieve(ht, "key-5") self.assertTrue(return_value is None) return_value = hash_table_retrieve(ht, "key-6") self.assertTrue(return_value is None) return_value = hash_table_retrieve(ht, "key-7") self.assertTrue(return_value is None) return_value = hash_table_retrieve(ht, "key-8") self.assertTrue(return_value is None) return_value = hash_table_retrieve(ht, "key-9") self.assertTrue(return_value is None)
def test_doesnt_shrink_if_still_initial_size(self): ht = HashTable(32) hash_table_insert(ht, 'first', 'test') self.assertEqual(ht.capacity, 32) hash_table_remove(ht, 'first') self.assertEqual(ht.capacity, 32)