def test_remove_removes_first_occurence_of_value_in_array(self):
        da = DynamicArray()
        da._n = 5
        da._capacity = 5
        da._A = da._make_array(da._capacity)
        da._A[0:5] = ['foo', 'bar', 'spam', 'baz', 'spam']
        expected_elements = ['foo', 'bar', 'baz', 'spam']

        da.remove('spam')

        self.assertEqual(da._A[0:4], expected_elements)
        self.assertEqual(da._n, 4)
    def test_remove_halves_array_capacity_if_less_than_quarter_of_capacity_used(
            self):
        da = DynamicArray()
        da._capacity = 64
        da._n = 17
        da._A = da._make_array(da._capacity)
        da._A[0:17] = [l for l in 'abcdefghijklmnopq']

        #  first remove() should not shrink the array, since with 16 elements
        #  we have not passed the N/4 threshold.
        da.remove('a')

        self.assertEqual(da._capacity, 64)

        #  second remove() should trigger halving the array capacity:
        da.remove('q')

        self.assertEqual(da._capacity, 32)