예제 #1
0
 def test_insert_with_extension_1(self):
     a = DynArray()
     for i in range(16):
         a.append(i)
     a.insert(1, 999)
     data = [a.capacity, a.__len__(), a.__getitem__(1)]
     res =  [32, 17, 999]
     self.assertEqual( data, res)
예제 #2
0
 def test_insert_in_range_first(self):
     a = DynArray()
     for i in range(10):
         a.append(i)
     a.insert(0, 0)
     data = [a.capacity, a.__len__(), a.__getitem__(0)]
     res =  [16, 11, 0]
     self.assertEqual( data, res)
예제 #3
0
 def test_insert_in_range_middle(self):
     a = DynArray()
     for i in range(10):
         a.append(i)
     a.insert(5, 999)
     data = [a.capacity, a.__len__(), a.__getitem__(5), a.__getitem__(6)]
     res =  [16, 11, 999, 5]
     self.assertEqual( data, res)
예제 #4
0
 def test_insert_in_range_last(self):
     a = DynArray()
     for i in range(15):
         a.append(i)
     a.insert(15, 999)
     data = [a.capacity, a.__len__(), a.__getitem__(15)]
     res =  [16, 16, 999]
     self.assertEqual( data, res)
예제 #5
0
 def test_radom_insert(self):
     for i in range(1000):
         count_element = random.randint(0, 16)
         a = DynArray()
         a_list = []
         for i in range(count_element):
             a.append(i)
         insert_index = -1
         while not (-1 < insert_index < count_element +1):
             insert_index = random.randint(0, 16)
         a.insert(insert_index, 999)
         #print(f'array size: {count_element}, insert index: {insert_index}')
         #for i in range(count_element + 1):
         #    a_list.append(a.__getitem__(i))
         #print(a_list)
         data = [a.__len__(), a.__getitem__(insert_index)]
         res = [count_element+1, 999]
         self.assertEqual(data, res)