Repository navigation
R50-T001: Lock down the contract of setBit (SetBit.js) [Bit-Manipulation/SetBit.js] - #99
Open
stavansomaiya wants to merge 1 commit into
Open
stavansomaiya wants to merge 1 commit into
stavansomaiya wants to merge 1 commit into
Conversation
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
e26b07f1064Bit-Manipulation/SetBit.js→setBit(line 29 at the pinned commit, line 42 after this PR)5c39e87·SetBit.js#L29stavansomaiya:student/e26b07f1064/R50-T001→S-AI-Projects:master(one commit on5c39e87)Summary
Adds focused contract regression tests for
setBitinBit-Manipulation/SetBit.js, plus a concise input/output contract in its JSDoc. Expected values were calculated by hand in binary before running the source, and every precondition is tied to a source line. Return values and argument mutation are tested separately.Files changed
Bit-Manipulation/SetBit.jssetBit(no logic change)Bit-Manipulation/test/SetBit.test.jsdescribe('setBit contract')work/R50-T001/(8 files)check.pyrunner,README.mdwrite-up,evidence.mjs,results.jsonand logs; coursework only, kept out of any upstream PRRelated Issue
Fixes: #1
This PR covers only R50-T001. Each of the 10 tasks has its own branch, commit and PR; see All 10 tasks under Additional Notes.
Type of Change
Changes Made
Bit-Manipulation/test/SetBit.test.js: 6 new tests. Smallest valid inputsetBit(0, 0) === 1; ordinary inputsetBit(5, 1) === 7; repeated value (bit already set)setBit(7, 1) === 7; 32-bit domain boundariessetBit(0, 30) === 1073741824andsetBit(0, 31) === -2147483648; arguments left unchanged.Bit-Manipulation/SetBit.js: JSDoc contract (zero-based position 0..31, signed 32-bit result, idempotent, pure) with two examples. No change to the implementation.work/R50-T001/:check.pyrunner,evidence.mjs(input / expected / actual / source line), recorded results, tool versions and command log.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, 10/10 passedAutomated check:
python3 work/R50-T001/check.py, exit 0Testing
Automated check:
python3 work/R50-T001/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 Bit-Manipulation/test/SetBit.test.jsnode work/R50-T001/evidence.mjscheck.pyrepeated value: setting a bit that is already set is a no-opnpm test(vitest run)npm run check-style(Prettier)codespellAcceptance criteria → evidence:
setBitin Bit-Manipulation/SetBit.js; every assertion has an explicit expected value.describe('setBit contract')) callsetBitdirectly and compare with literals:1,7,7,1073741824,-2147483648, and5/1for the arguments.setBitfrom Bit-Manipulation/SetBit.js. Write the literal inputs and independently calculated expected outputs in the tests before editing the implementation. The check must name the source line establishing each precondition.setBit(0, 0)→1; ordinarysetBit(5, 1)→7(0b101 | 0b010). Both were worked out in binary by hand; the implementation was never edited. Every fixture row inevidence.mjsnames its source line:SetBit.js:36(zero-based position),SetBit.js:6-7(32-bit operands),SetBit.js:13,SetBit.js:42-44.returnline is unchanged. The 4 existing tests pass, and the full suite passes (11976/11976).(5, 1), smallest(0, 0), repeated value(7, 1)→7(bit already set), plus the 32-bit boundaries bit 30 and bit 31.check.pyprints input / expected / actual for each row (6/6 match; see the terminal output above).Evidence files:
check.py·README.md(contract, fixture, baseline, findings) ·evidence.mjs·results.json·vitest-focused.jsonChecklist
Additional Notes
Baseline: every hand-calculated value matched the unmodified implementation, so no defect was found. Sensitivity check:
check.pyreplaces|with^(toggle instead of set) in a temporary copy, and the named testrepeated value: setting a bit that is already set is a no-opfails on it.Scope: the PR changes only
Bit-Manipulation/SetBit.js, its test file andwork/R50-T001/.work/R50-T001/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