def test_extend_dynamic(self): # extend_dynamic test test_object = ArrayList() for i in range(20): test_object.append(i) # Appending test_object.append(20) self.assertEqual(len(test_object), 21, "Extend_dynamic Append Error") self.assertEqual(len(test_object.array), 40, "Extend_dynamic Append Error") for i in range(19): test_object.append(i) self.assertEqual(len(test_object), 40, "Extend_dynamic Append Error") self.assertEqual(len(test_object.array), 40, "Extend_dynamic Append Error") # Inserting test_object.reset(20) for i in range(20): test_object.append(i) test_object.insert(0, 200) self.assertEqual(len(test_object), 21, "Extend_dynamic Append Error") self.assertEqual(len(test_object.array), 40, "Extend_dynamic Append Error") for i in range(19): test_object.insert(20 + i, i) self.assertEqual(len(test_object), 40, "Extend_dynamic Append Error") self.assertEqual(len(test_object.array), 40, "Extend_dynamic Append Error")
def test_insert(self): # insert test test_object = ArrayList() for i in range(5): test_object.append(i) test_object.insert(0, 11) self.assertEqual(str(test_object), "11\n0\n1\n2\n3\n4\n", "Insert Error") self.assertEqual(test_object[0], 11, "Insert Error") self.assertEqual(test_object[1], 0, "Insert Error") self.assertEqual(len(test_object), 6, "Insert Error") test_object.insert(-1, 12) self.assertEqual(str(test_object), "11\n0\n1\n2\n3\n12\n4\n", "Insert Error") self.assertEqual(test_object[-2], 12, "Insert Error") self.assertEqual(test_object[6], 4, "Insert Error") self.assertEqual(test_object[5], 12, "Insert Error") self.assertEqual(len(test_object), 7, "Insert Error")