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-7 resizeTable() method's test accepts this corrupted code #162

Open
obaibula opened this issue Mar 17, 2023 · 0 comments
Open

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

obaibula opened this issue Mar 17, 2023 · 0 comments

Comments

@obaibula
Copy link

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));
            }
        }
@obaibula obaibula changed the title 2-2-7 resizeTable() method's test accept this corrupted code 2-2-7 resizeTable() method's test accepts this corrupted code Mar 17, 2023
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