def test_search_resolution_overwrite(self): # Arrange key = 'key' value = 'value' ht = HashTable() ht.insert(key, value) # Act + Assert self.assertEqual(value, ht.search(key))
def test_search_resolution_chaning_without_collision(self): # Arrange key = 'key' value = 'value' ht = HashTable(container_type=LinkedList, resolution=HashTable.RESOLUTION_CHAINING) ht.insert(key, value) # Act + Assert self.assertEqual(value, ht.search(key))
def test_insert_resolution_chaning_no_collision(self): # Arrange key = 'key' value = 'value' ht = HashTable(container_type=LinkedList, resolution=HashTable.RESOLUTION_CHAINING) i = ht.i(key) # Act ht.insert(key, value) # Assert self.assertEqual(LinkedList((key,value)), ht.arr[i])
def test_insert_resolution_overwrite(self): # Arrange key = 'key' value = 'value' ht = HashTable() i = ht.i(key) # Act ht.insert(key, value) # Assert self.assertEqual(HashTable.Bucket((key,value)), ht.arr[i])
def setUp(self): """set up test case.""" self.hash_table = HashTable() self.hash_table["march 6"] = 130 self.hash_table["march 17"] = 204 self.hash_table["march 24"] = 210 self.hash_table["march 30"] = 207
def test_iteration_resolution_chaining(self): # Arrange ht = HashTable(container_type=LinkedList, resolution=HashTable.RESOLUTION_CHAINING, hash_function=lambda x: 1) ht.insert('key', 'value') ht.insert('key2', 'value2') ht.hash_function = lambda x: 2 ht.insert('key3', 'value3') # Act + Assert for (expected_key, expected_val), (actual_key, actual_val) in zip((('key', 'value'), ('key2', 'value2'), ('key3', 'value3')), ht): self.assertEqual(expected_key, actual_key) self.assertEqual(expected_val, actual_val)
def test_iteration_resolution_overwrite(self): # Arrange ht = HashTable() ht.insert('key', 'value') ht.insert('key2', 'value2') ht.hash_function = lambda x: 2 ht.insert('key3', 'value3') # Act + Assert for (expected_key, expected_val), (actual_key, actual_val) in zip((('key3', 'value3'), ('key2', 'value2'), ('key', 'value')), ht): self.assertEqual(expected_key, actual_key) self.assertEqual(expected_val, actual_val)
def test_delete_resolution_chaning_with_collision(self): # Arrange key = 'key' value = 'value' key2 = 'key2' value2 = 'value2' ht = HashTable() ht.insert(key, value) ht.insert(key2, value2) # Act ht.delete(key) # Assert self.assertIsNone(ht.search(key))
def test_search_resolution_chaning_with_collision(self): # Arrange key = 'key' value = 'value' key2 = 'key2' value2 = 'value2' ht = HashTable(container_type=LinkedList, resolution=HashTable.RESOLUTION_CHAINING, hash_function=lambda x: 1) ht.insert(key, value) ht.insert(key2, value2) # Act + Assert self.assertEqual((value, value2), (ht.search(key), ht.search(key2)))
def test_delete_resolution_overwrite(self): # Arrange key = 'key' value = 'value' ht = HashTable() ht.insert(key, value) # Act ht.delete(key) # Assert self.assertIsNone(ht.search(key))
def test_delete_resolution_chaning_without_collision(self): return # Arrange key = 'key' value = 'value' ht = HashTable(container_type=LinkedList, resolution=HashTable.RESOLUTION_CHAINING) ht.insert(key, value) # Act ht.delete(key) # Assert self.assertIsNone(ht.search(key))
if len(argv) < 3: exit('usage: ./main.py --type <' + '|'.join(data_structures) + '>') chosen_data_structure = argv[2] if argv[1] == '--type' and argv[2] not in data_structures: exit('invalid options') # default data structure data_structure = RBT() if chosen_data_structure == 'bst': data_structure = BST() elif chosen_data_structure == 'hmap': data_structure = HashTable(size=11549) # measure many different thigns actions_performed_count = dict() actions_performed_total_time = dict() actions_available = ['insert', 'load', 'delete', 'find', 'min', 'max', 'successor', 'inorder'] for a in actions_available: actions_performed_count[a] = 0 actions_performed_total_time[a] = 0 # measure total program running time total_running_time = 0 # remember the maximum amount of items stored max_items_stored = 0