class HashMapTests(unittest.TestCase): def setUp(self): self.hashmap = HashMap() def tearDown(self): self.hashmap = None # test if empty hashmap is empty def test_initialize_hashmap(self): self.assertTrue(self.hashmap.is_empty()) self.assertEqual(len(self.hashmap), 0) # test adding key into hashmap and getter method def test_insert_into_hashmap(self): self.assertFalse(self.hashmap.has_key("randomValue")) self.hashmap["FirstKey"] = "FirstValue" self.assertTrue(self.hashmap.has_key("FirstKey")) self.assertEqual(len(self.hashmap), 1) # test updating key in hashmap def test_update_in_hashmap(self): self.hashmap["FirstKey"] = "FirstValue" self.hashmap["SecondKey"] = "SecondValue" self.assertEqual("FirstValue", self.hashmap["FirstKey"]) # test deleting key in hashmap def test_delete_in_hashmap(self): self.hashmap["FirstKey"] = "FirstValue" self.hashmap.delete("FirstKey") self.assertFalse(self.hashmap.has_key("FirstKey")) self.assertIsNone(self.hashmap.get("FirstKey")) # test sections grow with an increase in # of key/values def test_hashmap_resize(self): self.assertEqual(6, self.hashmap.num_sections()) i = 1 while i <= 7: self.hashmap[i] = i i += 1 self.assertEqual(12, self.hashmap.num_sections()) # test for other hashmap to update old hashmap def test_hash_map_updates_with_other_hashmap(self): self.hashmap["FirstKey"] = "FirstValue" other_hashmap = HashMap() other_hashmap["FirstKey"] = "OtherFirstValue" other_hashmap["SeondKey"] = "SecondValue" self.hashmap.update(other_hashmap) self.assertEqual("OtherFirstValue", self.hashmap["FirstKey"])
from data import * from welcome import * from hashmap import HashMap from linkedlist import LinkedList #Printing the Welcome Message print_welcome() #Write code to insert food types into a data structure here. The data is in data.py food_types = Trie() food_types.make_trie(types) #Write code to insert restaurant data into a data structure here. The data is in data.py restaurants = HashMap(len(types)) for restaurant_datum in restaurant_data: key, value = restaurant_datum[0], restaurant_datum[1:] if not restaurants.has_key(key): restaurants.assign(key, LinkedList(value)) else: restaurants.retrieve(key).insert_beginning(value) #Write code for user interaction here while True: #start the loop by clearing any suggested words food_types.reset_words() user_input = str( input( "\nWhat type of food would you like to eat?\nType the beginning of that food type and press enter to see if it's here, or press 'Enter' with no input to see all options.\n" )).lower() #Search for user_input in food types data structure here res = food_types.return_suggestions(user_input) if res == -1: print("No other strings found with this prefix\n")