Open
Description
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
Labels
No labels