Пример #1
0
    def test_hash_table_removal(self):
        ht = BasicHashTable(8)

        hash_table_insert(ht, "key-1", "new-val-1")
        hash_table_remove(ht, "key-1")
        return_value = hash_table_retrieve(ht, "key-1")
        self.assertTrue(return_value is None)
    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)