Skip to content

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

Open
@Ohonovskiy

Description

@Ohonovskiy

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
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Ohonovskiy

        Issue actions

          2-2-5-array-list addShouldResizeDefaultCapacityWhenArrayIsFull fails when DEFAULT_CAPACITY > 6 · Issue #203 · bobocode-projects/java-fundamentals-exercises