Esempio n. 1
0
    def test_delete(self):
        m = HashMap()

        self.assertEqual(None, m.get('test'))

        for x in range(30):
            key = 'my_key_{}'.format(x)
            value = 'my value {}'.format(x)

            m.set(key, value)

        for x in range(30):
            key = 'my_key_{}'.format(x)
            value = 'my value {}'.format(x)

            self.assertEqual(value, m.get(key))

        m.delete('my_key_2')
        m.delete('my_key_7')
        m.delete('my_key_10')
        m.delete('my_key_18')
        m.delete('my_key_20')

        self.assertEqual(None, m.get('my_key_2'))
        self.assertEqual(None, m.get('my_key_7'))
        self.assertEqual(None, m.get('my_key_10'))
        self.assertEqual(None, m.get('my_key_18'))
        self.assertEqual(None, m.get('my_key_20'))
Esempio n. 2
0
    def test_capacity(self):
        m = HashMap()

        self.assertEqual(None, m.get('test'))

        m.set('my_key_1', 'my value 1')
        self.assertEqual(2, m.capacity)
        m.set('my_key_2', 'my value 2')
        self.assertEqual(2, m.capacity)
        m.set('my_key_3', 'my value 3')
        self.assertEqual(4, m.capacity)
        m.set('my_key_4', 'my value 4')
        self.assertEqual(8, m.capacity)
        m.set('my_key_5', 'my value 5')
        self.assertEqual(8, m.capacity)
        m.set('my_key_6', 'my value 6')
        self.assertEqual(16, m.capacity)
        m.set('my_key_7', 'my value 7')
        self.assertEqual(16, m.capacity)
        m.set('my_key_8', 'my value 8')
        self.assertEqual(16, m.capacity)
        m.set('my_key_9', 'my value 9')
        self.assertEqual(16, m.capacity)
        m.set('my_key_10', 'my value 10')
        self.assertEqual(32, m.capacity)
        m.set('my_key_11', 'my value 11')
        self.assertEqual(32, m.capacity)

        m.delete('my_key_11')
        self.assertEqual(32, m.capacity)
        m.delete('my_key_10')
        self.assertEqual(32, m.capacity)
        m.delete('my_key_9')
        self.assertEqual(32, m.capacity)
        m.delete('my_key_8')
        self.assertEqual(32, m.capacity)
        m.delete('my_key_8')
        self.assertEqual(16, m.capacity)
        m.delete('my_key_7')
        self.assertEqual(16, m.capacity)
        m.delete('my_key_6')
        self.assertEqual(16, m.capacity)
        m.delete('my_key_5')
        self.assertEqual(16, m.capacity)
        m.delete('my_key_4')
        self.assertEqual(16, m.capacity)
        m.delete('my_key_3')
        self.assertEqual(8, m.capacity)
        m.delete('my_key_2')
        self.assertEqual(8, m.capacity)
        m.delete('my_key_1')
        self.assertEqual(4, m.capacity)