Exemplo n.º 1
0
    def test_insert_doubles_array_capacity_if_capacity_reached(self):
        da = DynamicArray()
        da._n = 2
        da._capacity = 2
        da._A = da._make_array(da._capacity)
        da._A[0:2] = ['foo', 'bar']
        expected_result = 4

        da.insert(0, 'spam')
        result = da._capacity

        self.assertEqual(result, expected_result)
Exemplo n.º 2
0
    def test_insert_adds_at_index_shifts_items_rightward_with_positive_index(
            self):
        da = DynamicArray()
        da._n = 3
        da._capacity = 4
        da._A = da._make_array(da._capacity)
        elements = ['foo', 'bar', 'baz']
        da._A[0:3] = elements
        expected_elements = ['foo', 'spam', 'bar', 'baz']

        da.insert(1, 'spam')

        self.assertEqual(da._A[0:5], expected_elements)