Repository navigation
test(heap): cover heapify up when removing an item - #2224
Open
renanmpimentel wants to merge 1 commit into
Open
renanmpimentel wants to merge 1 commit into
renanmpimentel wants to merge 1 commit into
Conversation
The heapifyUp branch of Heap.remove could be deleted without any test failing: no existing case moves a smaller item into the removed slot below a larger parent. Add one that observes the heap right after the removal.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
heapifyUpbranch ofHeap.removeis not exercised by any test. Replacingwith nothing keeps all heap, priority-queue and heap-sort tests green (41/41), even though the heap property is then violated after such a removal.
Change
Test-only. Add a
MinHeapcase where the last item moved into the removed slot is smaller than its new parent, and assert the heap layout right afterremove():With the
heapifyUpbranch removed the new test fails (Received: "1,5,2,4,7,3"); onmasterit passes. Full suite: 588 tests pass, lint clean.Found with supertest: mutation testing plus statement-removal analysis, with every finding confirmed by running the regression against the unmodified test.