Repository navigation
R50-T007: Publish a runnable example for DisjointSetTreeNode (KruskalMST.js) [Graphs/KruskalMST.js] - #105
Open
stavansomaiya wants to merge 1 commit into
Conversation
…ests (R50-T007) Fixes: S-AI-Projects#7
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
e26b07f1064Graphs/KruskalMST.js→DisjointSetTreeNode(line 1 at the pinned commit, line 35 after this PR)5c39e87·KruskalMST.js#L1stavansomaiya:student/e26b07f1064/R50-T007→S-AI-Projects:master(one commit on5c39e87)@exampleis added and executed by a test that asserts its printed output. The implementation is unchanged.Summary
Adds executable documentation for
DisjointSetTreeNodeinGraphs/KruskalMST.js. The JSDoc@examplegoes from a new node, through two unions, to the final parents and ranks. It is executed by a test, and the displayed output is asserted.Decisive state transition: linking two roots of equal rank (
DisjointSetTree.link, lines 73-75) is the only step that raises a rank. Every other step followsparentlinks or hangs a shorter tree under a taller one with no rank change.Files changed
Graphs/KruskalMST.js@example; two classes exported (no logic change)Graphs/test/KruskalMST.test.jswork/R50-T007/(9 files)check.pyrunner,README.mdwrite-up,evidence.mjs,results.jsonand logs; coursework only, kept out of any upstream PRRelated Issue
Fixes: #7
This PR covers only R50-T007. Each of the 10 tasks has its own branch, commit and PR; see All 10 tasks under Additional Notes.
Type of Change
Changes Made
Graphs/KruskalMST.js: JSDoc and a runnable@exampleforDisjointSetTreeNode.DisjointSetTreeNodeandDisjointSetTreeare now also exported, so the example imports them by their real names.GraphWeightedUndirectedAdjacencyListis unchanged and there is no logic change.Graphs/test/KruskalMST.test.js(new; there was no test file before). It reads the@examplefrom the source, checks that itsimportline names real exports, runs it, and asserts the printed linesa true 0,b 1,b 1,0 0. It also asserts the hand-calculated states (union('a','b')→a.parent = b,b.rank = 1;union('c','a')→cunderb, ranks unchanged). The commented-out MST example at the bottom of the file becomes an assertion.work/R50-T007/:check.py,trace.txt(the traced execution, which matched the hand calculation), andevidence.mjs, which also runs the example verbatim withnode(real import line) and compares stdout. Plus 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, 5/5 passedAutomated check:
python3 work/R50-T007/check.py, exit 0Testing
Automated check:
python3 work/R50-T007/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 Graphs/test/KruskalMST.test.jsnode work/R50-T007/evidence.mjscheck.pyprints exactly what the comments next to each console.log saynpm test(vitest run)npm run check-style(Prettier)codespellAcceptance criteria → evidence:
DisjointSetTreeNodein Graphs/KruskalMST.js; every assertion has an explicit expected value.a true 0,b 1,b 1,0 0. The state tests assert literal parents and ranks, and the MST test asserts the literal kept edges.DisjointSetTreeNodefrom Graphs/KruskalMST.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.new DisjointSetTreeNode('a')is its own parent with rank 0 (lines 38-39). Ordinary:union('a', 'b')thenunion('c', 'a'), worked out by hand in the README and confirmed bytrace.txt. The rank rule is cited at lines 73-75.GraphWeightedUndirectedAdjacencyListis unchanged, and the two classes are only newly exported. No logic change. The full suite passes (11975/11975).prints exactly what the comments next to each console.log sayreads the@examplestraight from the source, checks that itsimportnames real exports, runs it, and compares each printed line with the documented one.evidence.mjsalso runs the example verbatim withnode.DisjointSetTree.link, lines 73-75) is the only step that raises a rank.Evidence files:
check.py·README.md(contract, fixture, baseline, findings) ·evidence.mjs·results.json·vitest-focused.jsonChecklist
Additional Notes
Sensitivity check: changing
y.rank += 1toy.rank += 2in a temporary copy makes the doc-example test fail (printsb 2, documentedb 1).Scope: the PR changes only
Graphs/KruskalMST.js, its test file andwork/R50-T007/.work/R50-T007/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