示例#1
0
    def test_insert_out_of_bound(self):
        d = DynArray()

        for i in range(0, 10):
            d.append(i)

        with self.assertRaises(IndexError):
            d.insert(11, 10)
示例#2
0
    def test_insert_without_overflow(self):
        d = DynArray()
        count = 10

        for i in range(0, count):
            d.append(i)

        d.insert(8, 10)

        self.assertEqual(d.count, count + 1)
        self.assertEqual(d.capacity, 16)
示例#3
0
    def test_insert_out_of_bound(self):
        d = DynArray()
        count = 10

        for i in range(0, count):
            d.append(i)

        with self.assertRaises(IndexError):
            d.delete(-1)

        with self.assertRaises(IndexError):
            d.delete(count + 1)
示例#4
0
    def test_delete_without_resizing(self):
        d = DynArray()
        count = 8
        capacity = d.capacity

        for i in range(0, count):
            d.append(i)

        d.delete(3)

        self.assertEqual(d.count, count - 1)
        self.assertEqual(d.capacity, capacity)
示例#5
0
    def test_insert_with_overflow(self):
        d = DynArray()
        count = 16
        capacity = d.capacity

        for i in range(0, count):
            d.append(i)

        d.insert(16, 16)

        self.assertEqual(d.count, count + 1)
        self.assertEqual(d.capacity, capacity * 2)
示例#6
0
    def test_delete_without_resizing(self):
        d = DynArray()
        count = 20
        capacity = d.capacity

        for i in range(0, count):
            d.append(i)

        self.assertEqual(d.count, count)
        self.assertEqual(d.capacity, capacity * 2)

        for i in range(0, 5):
            d.delete(i)

        self.assertEqual(d.capacity, 21)

        for i in range(0, 5):
            d.delete(i)

        self.assertEqual(d.count, count / 2)
        self.assertEqual(d.capacity, 16)
示例#7
0
 def setUp(self):
     self.array = DynArray()