Пример #1
0
    def test_set_and_get(self):
        hash_table = MyHash()
        # test basic set and get functionality for strings
        hash_table.set('hello', 'world')
        self.assertEqual(hash_table.get('hello'), 'world')

        # test basic set and get functionality for ints
        hash_table.set(3, 5)
        self.assertEqual(hash_table.get(3), 5)

        # test basic set and get functionality for objects
        class test(object):
            pass

        class test2(object):
            pass

        key = test()
        val = test2()

        hash_table.set(key, val)
        self.assertIsInstance(hash_table.get(key), test2)

        # test for invalid key
        self.assertRaises(KeyError, hash_table.get, 'test')