Ejemplo n.º 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())
Ejemplo n.º 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)
Ejemplo n.º 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"]
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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())
Ejemplo n.º 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))
Ejemplo n.º 9
0
 def test_attrerror(self):
     d = Dict()
     with self.assertRaises(AttributeError):
         value = d.empty
Ejemplo n.º 10
0
 def test_keyerror(self):
     d = Dict()
     with self.assertRaises(KeyError):
         value = d['empty']
Ejemplo n.º 11
0
 def test_attr(self):
     d = Dict()
     d.age = 25
     self.assertTrue('age' in d)
     self.assertEqual(d['age'],25)
Ejemplo n.º 12
0
 def test_key(self):
     d = Dict()
     d['key'] = 'value'
     self.assertEqual(d.key, 'value')