Пример #1
0
 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")
Пример #2
0
 def test_eq(self):
     # __eq__ test
     test_object = ArrayList()
     # test case 1
     for i in range(5):
         test_object.append(i)
     self.assertNotEqual(test_object, [0, 1, 2, 3, 4, 5], "__eq__ Error")
     self.assertEqual(test_object, [0, 1, 2, 3, 4], "__eq__ Error")
     self.assertNotEqual(test_object, [0, 1, 2, 3, 5], "__eq__ Error")
     # test case 2
     test_object = test_object.reset(27)
     other = []
     for i in range(27):
         test_object.append(i)
         other.append(i)
     self.assertEqual(test_object, other, "__eq__ Error")
Пример #3
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")
Пример #4
0
 def test_reset(self):
     # reset test
     a_object = ArrayList()
     a_object.reset(40)
     # test case 1: 40
     self.assertEqual(len(a_object.array), 40, "Reset Array Error")
     self.assertEqual(a_object.count, 0, "Reset Array Error")
     # test case 2: 60
     a_object.reset(60)
     self.assertEqual(len(a_object.array), 60, "Reset Array Error")
     self.assertEqual(a_object.count, 0, "Reset Array Error")
     # test case 3: 20
     a_object.reset(20)
     self.assertEqual(len(a_object.array), 20, "Reset Array Error")
     self.assertEqual(a_object.count, 0, "Reset Array Error")