Пример #1
0
 def test_overwrite_value(self):
     my_dict = Dict()
     my_dict['x'] = 1
     self.assertIn(("x", 1), my_dict.items())
     my_dict['x'] = 2
     self.assertIn(("x", 2), my_dict.items())
     self.assertNotIn(("x", 1), my_dict.items())
Пример #2
0
    def test_fill_up_storage_multiple_times(self):
        my_dict = Dict()
        for i in range(my_dict.INITIAL_STORAGE_LENGTH):
            my_dict[i] = i
        self.assertEqual(my_dict._storage_length,
                         my_dict.INITIAL_STORAGE_LENGTH)

        for i in range(my_dict.INITIAL_STORAGE_LENGTH,
                       my_dict.INITIAL_STORAGE_LENGTH * 2):
            my_dict[i] = i
        self.assertEqual(my_dict._storage_length,
                         my_dict.INITIAL_STORAGE_LENGTH * 2)

        for i in range(my_dict.INITIAL_STORAGE_LENGTH * 2,
                       my_dict.INITIAL_STORAGE_LENGTH * 4):
            my_dict[i] = i
        self.assertEqual(my_dict._storage_length,
                         my_dict.INITIAL_STORAGE_LENGTH * 4)

        for i in range(my_dict.INITIAL_STORAGE_LENGTH * 4,
                       my_dict.INITIAL_STORAGE_LENGTH * 8):
            my_dict[i] = i
        self.assertEqual(my_dict._storage_length,
                         my_dict.INITIAL_STORAGE_LENGTH * 8)

        my_dict['a'] = 1
        self.assertEqual(my_dict._storage_length,
                         my_dict.INITIAL_STORAGE_LENGTH * 16)
Пример #3
0
 def test_create_empty_Dict(self):
     my_dict = Dict()
     self.assertIsInstance(my_dict, Dict)
     self.assertEqual(my_dict._storage_length,
                      my_dict.INITIAL_STORAGE_LENGTH)
     self.assertEqual(my_dict.items(), [])
     with self.assertRaises(KeyError):
         my_dict["x"]
Пример #4
0
 def test_fill_up_storage(self):
     my_dict = Dict()
     for i in range(my_dict.INITIAL_STORAGE_LENGTH):
         my_dict[i] = i
     self.assertEqual(my_dict._storage_length,
                      my_dict.INITIAL_STORAGE_LENGTH)
     my_dict['a'] = 1
     self.assertEqual(my_dict._storage_length,
                      my_dict.INITIAL_STORAGE_LENGTH * 2)
Пример #5
0
 def test_setting_Dict_value(self):
     my_dict = Dict()
     my_dict['y'] = 2
     self.assertIn(("y", 2), my_dict.items())
     self.assertEqual(my_dict["y"], 2)
Пример #6
0
 def test_initialize_Dict_with_element(self):
     my_dict = Dict(("x", 1))
     self.assertEqual(my_dict.items(), [("x", 1)])
     self.assertEqual(my_dict["x"], 1)
Пример #7
0
 def test_initialize_Dict_with_multiple_elements(self):
     my_dict = Dict(("x", 1), ("y", 2))
     self.assertIn(("x", 1), my_dict.items())
     self.assertIn(("y", 2), my_dict.items())
Пример #8
0
 def test_init(self):
     d = Dict(a = 1, b = 'test')
     self.assertEqual(d.a, 1)
     self.assertEqual(d.b, 'test')
     self.assertTrue(isinstance(d, dict))
Пример #9
0
 def test_attrerror(self):
     d = Dict()
     with self.assertRaises(AttributeError):
         value = d.empty
Пример #10
0
 def test_keyerror(self):
     d = Dict()
     with self.assertRaises(KeyError):
         value = d['empty']
Пример #11
0
 def test_attr(self):
     d = Dict()
     d.age = 25
     self.assertTrue('age' in d)
     self.assertEqual(d['age'],25)
Пример #12
0
 def test_key(self):
     d = Dict()
     d['key'] = 'value'
     self.assertEqual(d.key, 'value')