示例#1
0
    def test_overwrite_same_key(self):
        obj = hash_map.HashMap(10)
        obj.set('a', 15)
        self.assertEqual(obj.get('a'), 15)

        obj.set('a', 25)
        self.assertEqual(obj.get('a'), 25)
示例#2
0
    def test_delete(self):
        obj = hash_map.HashMap(10)
        obj.set('c', 15)
        obj.set('d', 25)
        deleted = obj.delete('c')

        self.assertRaises(KeyError, obj.get, 'c')
        self.assertEqual(deleted, ('c', 15))
        self.assertEqual(obj.get('d'), 25)
示例#3
0
    def test_set_large_data_set(self):
        obj = hash_map.HashMap()
        self.assertEqual(obj.capacity, 500)
        self.assertEqual(obj.size, 0)

        for index in range(1000):
            obj.set(index, 'test' + str(index))

        self.assertGreater(obj.capacity, 500)
        self.assertEqual(obj.size, 1000)
        self.assertEqual(obj.get(999), 'test999')
示例#4
0
    def test_hash_map_resize_up(self):
        obj = hash_map.HashMap(10)
        self.assertEqual(obj.capacity, 10)
        self.assertEqual(obj.size, 0)

        for index in range(15):
            obj.set(index, 'test' + str(index))

        self.assertGreater(obj.capacity, 10)
        self.assertEqual(obj.size, 15)
        self.assertEqual(obj.get(14), 'test14')
示例#5
0
    def test_set_with_string_key(self):
        obj = hash_map.HashMap()
        obj.set('test', 25)

        self.assertEqual(obj.get('test'), 25)
示例#6
0
    def test_set_with_number_key(self):
        obj = hash_map.HashMap()
        obj.set(5, 'test')

        self.assertEqual(obj.get(5), 'test')
示例#7
0
    def test_create_with_capacity(self):
        obj = hash_map.HashMap(25)

        self.assertEqual(obj.capacity, 25)
        self.assertEqual(obj.size, 0)
示例#8
0
    def test_bad_delete(self):
        obj = hash_map.HashMap(10)
        obj.set('e', 30)

        self.assertRaises(KeyError, obj.delete, 'w')
        self.assertEqual(obj.get('e'), 30)
示例#9
0
    def test_bad_get(self):
        obj = hash_map.HashMap(10)
        obj.set('b', 25)

        self.assertRaises(KeyError, obj.get, 'c')
示例#10
0
    def test_set_and_get(self):
        obj = hash_map.HashMap()
        obj.set('a', 15)

        self.assertEqual(obj.get('a'), 15)
示例#11
0
    def test_create_with_default_capacity(self):
        obj = hash_map.HashMap()

        self.assertEqual(obj.capacity, 500)
        self.assertEqual(obj.size, 0)
 def setUp(self):
     self.SUT = hash_map.HashMap()
 def test_opacity(self):
     self.SUT = hash_map.HashMap(4)
     self.assertEqual(self.SUT.capacity, 4)