def test_add_and_retrieve_multiple_letters(self): d = MyDictionary() d.insert('a') d.insert('b') d.insert('c') self.assertEqual('a', d.lookUp('a')) self.assertEqual('b', d.lookUp('b')) self.assertEqual('c', d.lookUp('c'))
def test_resize(self): d = MyDictionary(100) # insert a, aa, aaa, etc.. for i in range(72, 72+100): d.insert(chr(i)) self.assertEqual('H', d.lookUp('H')) self.assertEqual('J', d.lookUp('J')) self.assertEqual(100, d.entries) self.assertTrue(d.size() > 50) self.assertEqual(200, d.capacity) print(d.d)
def test_resize(self): d = MyDictionary(100) # insert a, aa, aaa, etc.. for i in range(72, 72 + 100): d.insert(chr(i)) self.assertEqual('H', d.lookUp('H')) self.assertEqual('J', d.lookUp('J')) self.assertEqual(100, d.entries) self.assertTrue(d.size() > 50) self.assertEqual(200, d.capacity) print(d.d)
import re from ex5.my_dictionary import MyDictionary my_dict = MyDictionary(500) with open('input_ex3.txt') as f: for line in f.readlines(): words = re.findall('[a-zA-Z]{3,}[., \n]', line) for word in words: try: my_dict.insert(word.strip()) except KeyError as e: pass #dont care print("Size: {}".format(my_dict.size())) print("Capacity: {}".format(my_dict.capacity)) collisions = 0 max_collision_count = 0 for list in my_dict.d: # only values above 1 are considered as collision if len(list) > 1: current_collision_count = len(list) - 1 collisions += current_collision_count if (current_collision_count > max_collision_count): max_collision_count = current_collision_count print("Max collision count: {}".format(max_collision_count)) print("Collisions overall: {}".format(collisions))
def test_add_and_retrieve_single_letter(self): d = MyDictionary() d.insert('a') self.assertEqual('a', d.lookUp('a'))
def test_add_same_letter_twice_should_error(self): d = MyDictionary() d.insert('a') with self.assertRaises(KeyError): d.insert('a')