コード例 #1
0
 def test_remove(self):
     # remove test
     test_object = ArrayList()
     for i in range(5):
         test_object.append(i)
     # test case 1
     test_object.remove(3)
     self.assertEqual(str(test_object), "0\n1\n2\n4\n", "Remove Error")
     self.assertEqual(test_object[3], 4, "Remove Error")
     self.assertEqual(len(test_object), 4, "Remove Error")
     # test case 2
     test_object.remove(0)
     self.assertEqual(str(test_object), "1\n2\n4\n", "Remove Error")
     self.assertEqual(test_object[2], 4, "Remove Error")
     self.assertEqual(len(test_object), 3, "Remove Error")
コード例 #2
0
 def test_shrink_dynamic(self):
     # shrink_dynamic test
     test_object = ArrayList()
     for i in range(40):
         test_object.append(i)
     # delete test case 1
     for i in range(35):
         test_object.delete(0)
     self.assertEqual(len(test_object), 5, "Shrink_dynamic Delete Error")
     self.assertEqual(len(test_object.array), 40,
                      "Shrink_dynamic Delete Error")
     test_object.delete(0)
     self.assertEqual(len(test_object), 4, "Shrink_dynamic Delete Error")
     self.assertEqual(len(test_object.array), 20,
                      "Shrink_dynamic Delete Error")
     # delete test case 2
     test_object.reset(160)
     for i in range(160):
         test_object.append(i)
     for i in range(140):
         test_object.delete(0)
     self.assertEqual(len(test_object), 20, "Shrink_dynamic Delete Error")
     self.assertEqual(len(test_object.array), 160,
                      "Shrink_dynamic Delete Error")
     test_object.delete(0)
     self.assertEqual(len(test_object), 19, "Shrink_dynamic Delete Error")
     self.assertEqual(len(test_object.array), 80,
                      "Shrink_dynamic Delete Error")
     # remove test case 1
     test_object.reset(40)
     for i in range(40):
         test_object.append(i)
     for i in range(35):
         test_object.remove(i)
     self.assertEqual(len(test_object), 5, "Shrink_dynamic Delete Error")
     self.assertEqual(len(test_object.array), 40,
                      "Shrink_dynamic Delete Error")
     test_object.remove(35)
     self.assertEqual(len(test_object), 4, "Shrink_dynamic Delete Error")
     self.assertEqual(len(test_object.array), 20,
                      "Shrink_dynamic Delete Error")
     # remove test case 2
     test_object.reset(160)
     for i in range(160):
         test_object.append(i)
     for i in range(140):
         test_object.remove(i)
     self.assertEqual(len(test_object), 20, "Shrink_dynamic Delete Error")
     self.assertEqual(len(test_object.array), 160,
                      "Shrink_dynamic Delete Error")
     test_object.remove(140)
     self.assertEqual(len(test_object), 19, "Shrink_dynamic Delete Error")
     self.assertEqual(len(test_object.array), 80,
                      "Shrink_dynamic Delete Error")