Repository navigation
R50-T003: Cross-check getParentPosition (KeyPriorityQueue.js) [Data-Structures/Heap/KeyPriorityQueue.js] - #101
Open
stavansomaiya wants to merge 1 commit into
Conversation
…dent references (R50-T003) Fixes: S-AI-Projects#3
This was referenced Nov 23, 2026
Open
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.
Description
e26b07f1064Data-Structures/Heap/KeyPriorityQueue.js→getParentPosition(line 22 at the pinned commit, line 36 after this PR)5c39e87·KeyPriorityQueue.js#L22stavansomaiya:student/e26b07f1064/R50-T003→S-AI-Projects:master(one commit on5c39e87)Summary
Compares
getParentPositioninData-Structures/Heap/KeyPriorityQueue.jswith two independent oracles that never call it. One is a hand-reviewed explicit table for positions 0..24. The other is a different method: the 1-based bit-shift rule((p + 1) >> 1) - 1, checked for positions 0..63. The PR also locks down the FIFO fixture (A, B, C, D) and the empty-state behaviour.Files changed
Data-Structures/Heap/KeyPriorityQueue.jsgetParentPositionexported (no logic change)Data-Structures/Heap/test/KeyPriorityQueue.test.jswork/R50-T003/(9 files)check.pyrunner,README.mdwrite-up,evidence.mjs,results.jsonand logs; coursework only, kept out of any upstream PRRelated Issue
Fixes: #3
This PR covers only R50-T003. Each of the 10 tasks has its own branch, commit and PR; see All 10 tasks under Additional Notes.
Type of Change
Changes Made
Data-Structures/Heap/test/KeyPriorityQueue.test.js: 25 explicit-table tests, the bit-shift oracle comparison, and a representative result (getParentPosition(4) === 1). The fixture is push A, B, C; pop twice; push D; drain. After every operation it checks the explicit removed key and size, and that a plain-array FIFO reference agrees. Also tests that separate instances do not share contents (checked both ways).Data-Structures/Heap/KeyPriorityQueue.js: JSDoc explaining one representative result (getParentPosition(4) === 1, because node 1 has children 3 and 4) and the-1root sentinel.getParentPositionis now also exported. No logic change.work/R50-T003/:check.py,evidence.mjs(one row per position and per fixture step) and results.Screenshots / Recordings
There is no UI, so the recording is the terminal output of a fresh run on 23 Nov 2026. The run used a clean checkout of this branch with a new
npm cifrom the lockfile. The output is copied verbatim; only the temporary checkout path is replaced by a label.Focused tests:
npx vitest run … --reporter=verbose, 38/38 passedAutomated check:
python3 work/R50-T003/check.py, exit 0Testing
Automated check:
python3 work/R50-T003/check.pyinstalls from the lockfile and runs the focused tests. It then prints input / expected / actual for every fixture row, runs each deliberate mutant in a temporary copy, and finally runs the repository test script in non-watch mode. It exits non-zero if any assertion or step fails, and records every command incommands.log.To reproduce:
Recorded results (committed in
results.json; tool versions inversions.txt):npm ci --ignore-scripts --no-audit --no-fundvitest run Data-Structures/Heap/test/KeyPriorityQueue.test.jsnode work/R50-T003/evidence.mjscheck.pyexplicit table: parent of position 0 is -1npm test(vitest run)npm run check-style(Prettier)codespellAcceptance criteria → evidence:
getParentPositionin Data-Structures/Heap/KeyPriorityQueue.js; every assertion has an explicit expected value.explicit table: parent of position N is M(25 tests, N = 0..24) each assert a literal M.representative resultassertsgetParentPosition(4)is1. The queue test asserts literal keys'A'..'D'and a literal size after every step.enqueue A, B, C; remove twice; insert D; drain -> A, B, C, Dchecks the removed key and the size after every operation, against both a literal and a plain-array FIFO reference. Final order:['A', 'B', 'C', 'D']. The documented empty state (isEmpty() === true, size 0) is checked before the first push and after draining.separate instances do not share contentschecks isolation in both directions.((p + 1) >> 1) - 1, for positions 0..63. Neither callsgetParentPosition.Math.floor(position / 2)the minimal reproducible case isgetParentPosition(0)(expected-1, mutant0), documented in the README.Evidence files:
check.py·README.md(contract, fixture, baseline, findings) ·evidence.mjs·results.json·vitest-focused.jsonChecklist
Additional Notes
No mismatch on any of the 89 compared positions. Sensitivity check:
Math.floor(position / 2)in a temporary copy is caught; the minimal reproducible case isgetParentPosition(0)(expected-1, mutant0), reported by the named testexplicit table: parent of position 0 is -1. Out of scope and only recorded:pop()on an empty queue leaves a stray"-1"property on_heap.Scope: the PR changes only
Data-Structures/Heap/KeyPriorityQueue.js, its test file andwork/R50-T003/.work/R50-T003/is coursework evidence and would be removed from any later upstream PR.All 10 tasks (one PR each)
R50-T001R50-T002R50-T003R50-T004R50-T005R50-T006R50-T007R50-T008R50-T009R50-T010