Esempio n. 1
0
    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))
Esempio n. 2
0
    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))
Esempio n. 3
0
    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])
Esempio n. 4
0
    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
Esempio n. 6
0
    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)
Esempio n. 7
0
    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)
Esempio n. 8
0
    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))
Esempio n. 9
0
    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)))
Esempio n. 10
0
    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))
Esempio n. 11
0
    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))
Esempio n. 12
0
    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