Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2-2-5-array-list addShouldResizeDefaultCapacityWhenArrayIsFull fails when DEFAULT_CAPACITY > 6 #203

Open
Ohonovskiy opened this issue Nov 24, 2024 · 0 comments

Comments

@Ohonovskiy
Copy link

Ohonovskiy commented Nov 24, 2024

test doesn't trigger resizing due to less items added than needed (DEFAULT_CAPACITY for java.utilArrayList is 16).
possible fix:

@Test
@Order(12)
void addShouldResizeDefaultCapacityWhenArrayIsFull() {
    arrayList = new ArrayList<>();
    int defaultCapacity = getTestArray().length;

    for (int i = 0; i < defaultCapacity + 1; i++) {
        arrayList.add(i); // Add enough elements to exceed the default capacity
    }

    assertThat(getTestArray().length).isGreaterThan(defaultCapacity); // Ensure the array has grown
    assertThat(getTestSize()).isEqualTo(defaultCapacity + 1); // Ensure the size reflects all added elements
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant