Skip to content

2-2-7 resizeTable() method's test accepts this corrupted code #162

Description

@obaibula

The accepted corrupted code:

@SuppressWarnings("unchecked")
    public void resizeTable(int newCapacity) {
        Node<K, V>[] newTable = new Node[newCapacity];
        for (int i = 0; i < table.length; i++){
            int newIndex = calculateIndex(table[i], newCapacity);
            newTable[newIndex] = table[i];
        }
        table = newTable;
    }

Please, consider my test variation:

@Test
        @Order(1)
        @DisplayName("resizeTable creates a new array and put there all elements")
        void resizeTable() {
            for(int i = 10; i < 40; i++){
                addToTable(String.valueOf(i), i % 7);
            }

            hashTable.resizeTable(64);

            assertThat(getInternalTable(hashTable)).hasSize(64);

            for(int i = 10; i < 40; i++){
                assertTrue(checkKeyValueExists(String.valueOf(i), i % 7));
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions