Skip to content

R50-T005: Make verification repeatable for newGeneration (ConwaysGameOfLife.js) [Cellular-Automata/ConwaysGameOfLife.js] - #103

Open
stavansomaiya wants to merge 1 commit into
S-AI-Projects:masterfrom
stavansomaiya:student/e26b07f1064/R50-T005
Open

stavansomaiya wants to merge 1 commit into
S-AI-Projects:masterfrom
stavansomaiya:student/e26b07f1064/R50-T005

Conversation

@stavansomaiya

@stavansomaiya stavansomaiya commented Nov 23, 2026 •

Copy link
Copy Markdown

Description

Task R50-T005 · task 5 of 10 · Deterministic execution
Issue #5 · Make verification repeatable for newGeneration
Student Stavan Somaiya · URN e26b07f1064
File → function Cellular-Automata/ConwaysGameOfLife.js → newGeneration (line 14 at the pinned commit, line 24 after this PR)
Pinned source TheAlgorithms/JavaScript @ 5c39e87 · ConwaysGameOfLife.js#L14
Branch stavansomaiya:student/e26b07f1064/R50-T005 → S-AI-Projects:master (one commit on 5c39e87)
Outcome The function is already pure, so no dependency seam was needed. The implementation is unchanged.

Summary

newGeneration in Cellular-Automata/ConwaysGameOfLife.js is already pure: no time, randomness, I/O, network, UI or module state. So no dependency seam was introduced, and therefore no new parameter that would need a default. Instead this adds repeatability and input-isolation regression tests and documents the contract.

Files changed

File Lines What changed
Cellular-Automata/ConwaysGameOfLife.js +10 / −0 JSDoc stating the determinism / isolation contract (no logic change)
Cellular-Automata/test/ConwaysGameOfLife.test.js +79 / −0 8 repeatability and input-isolation tests
work/R50-T005/ (8 files) evidence check.py runner, README.md write-up, evidence.mjs, results.json and logs; coursework only, kept out of any upstream PR

Related Issue

Fixes: #5

This PR covers only R50-T005. Each of the 10 tasks has its own branch, commit and PR; see All 10 tasks under Additional Notes.

Type of Change

  • Bug Fix
  • New Feature
  • UI/UX Improvement
  • Performance Improvement
  • Tests
  • Documentation
  • Refactoring / Maintenance
  • CI/CD

Changes Made

  • Cellular-Automata/test/ConwaysGameOfLife.test.js: covers:
    • smallest inputs: [] → [] and [[1]] → [[0]];
    • an ordinary glider step, with the expected grid worked out by hand;
    • the input is unchanged after the call;
    • a deeply frozen input is accepted (strict mode would throw on any write);
    • the output shares no rows with the input;
    • the same fixture gives the same result twice from fresh copies;
    • a later call is unaffected by an earlier call on another input whose result was then tampered with.
  • Cellular-Automata/ConwaysGameOfLife.js: JSDoc stating determinism, no external dependencies, no mutation, non-wrapping edges, and the params and return value. No logic change.
  • work/R50-T005/: check.py and evidence.mjs, which also scans the real source (comments removed) for time, randomness, I/O, globals, imports and module-level variables and finds none. 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 ci from the lockfile. The output is copied verbatim; only the temporary checkout path is replaced by a label.

Focused tests: npx vitest run … --reporter=verbose, 9/9 passed
$ npx vitest run Cellular-Automata/test/ConwaysGameOfLife.test.js --reporter=verbose
 RUN  v1.2.1 <clean checkout of student/e26b07f1064/R50-T005>
 ✓ Cellular-Automata/test/ConwaysGameOfLife.test.js > newGeneration > should produce the next generation according to the rules
 ✓ Cellular-Automata/test/ConwaysGameOfLife.test.js > newGeneration is deterministic and isolates its input > smallest valid input: an empty grid gives an empty grid
 ✓ Cellular-Automata/test/ConwaysGameOfLife.test.js > newGeneration is deterministic and isolates its input > smallest non-empty grid: a lone live cell dies
 ✓ Cellular-Automata/test/ConwaysGameOfLife.test.js > newGeneration is deterministic and isolates its input > ordinary input: one glider step
 ✓ Cellular-Automata/test/ConwaysGameOfLife.test.js > newGeneration is deterministic and isolates its input > does not modify the input grid
 ✓ Cellular-Automata/test/ConwaysGameOfLife.test.js > newGeneration is deterministic and isolates its input > accepts a deeply frozen grid, so it never writes to its input
 ✓ Cellular-Automata/test/ConwaysGameOfLife.test.js > newGeneration is deterministic and isolates its input > returns a new grid that shares no rows with the input
 ✓ Cellular-Automata/test/ConwaysGameOfLife.test.js > newGeneration is deterministic and isolates its input > same input twice in fresh state gives the same result
 ✓ Cellular-Automata/test/ConwaysGameOfLife.test.js > newGeneration is deterministic and isolates its input > an earlier call with another input cannot change a later result
 Test Files  1 passed (1)
      Tests  9 passed (9)
Automated check: python3 work/R50-T005/check.py, exit 0
$ python3 work/R50-T005/check.py
[PASS] smallest valid input: empty grid
       input:    []
       expected: []
       actual:   []
       source:   ConwaysGameOfLife.js:24-25 loops over cells.length (0 rows)
[PASS] smallest non-empty grid: lone cell dies
       input:    [[1]]
       expected: [[0]]
       actual:   [[0]]
       source:   ConwaysGameOfLife.js:6 rule 3, live cell with 0 neighbours dies
[PASS] ordinary input: glider step
       input:    [[0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [1, 1, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
       expected: [[0, 0, 0, 0, 0], [1, 0, 1, 0, 0], [0, 1, 1, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0]]
       actual:   [[0, 0, 0, 0, 0], [1, 0, 1, 0, 0], [0, 1, 1, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0]]
       source:   ConwaysGameOfLife.js:4-5 rules 1 and 2
[PASS] input grid unchanged after call
       input:    [[0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [1, 1, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
       expected: [[0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [1, 1, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
       actual:   [[0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [1, 1, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
       source:   ConwaysGameOfLife.js:43 cells are only read
[PASS] output shares no rows with input
       input:    "glider"
       expected: {"sameGrid": false, "sharedRows": 0}
       actual:   {"sameGrid": false, "sharedRows": 0}
       source:   ConwaysGameOfLife.js:25,27 new arrays are created
[PASS] glider run twice, then again after another input (result tampered)
       input:    "glider x3"
       expected: [[[0, 0, 0, 0, 0], [1, 0, 1, 0, 0], [0, 1, 1, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0], [1, 0, 1, 0, 0], [0, 1, 1, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0], [1, 0, 1, 0, 0], [0, 1, 1, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0]]]
       actual:   [[[0, 0, 0, 0, 0], [1, 0, 1, 0, 0], [0, 1, 1, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0], [1, 0, 1, 0, 0], [0, 1, 1, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0], [1, 0, 1, 0, 0], [0, 1, 1, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0]]]
       source:   ConwaysGameOfLife.js:24 no module-level state
[PASS] external dependencies found by scanning the source (comments removed)
       input:    "Date, Math, performance, process, require, import, fetch, console, timers, globals"
       expected: []
       actual:   []
       source:   ConwaysGameOfLife.js:24-54 body uses only its parameter and local variables
[PASS] module-level variables (shared state between calls)
       input:    "top-level let/var/const declarations"
       expected: []
       actual:   []
       source:   ConwaysGameOfLife.js: only an exported function is declared
[PASS] deeply frozen input is accepted (no write is attempted)
       input:    "Object.freeze(glider)"
       expected: [[0, 0, 0, 0, 0], [1, 0, 1, 0, 0], [0, 1, 1, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0]]
       actual:   [[0, 0, 0, 0, 0], [1, 0, 1, 0, 0], [0, 1, 1, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0]]
       source:   ConwaysGameOfLife.js:43 cells are only read
[KILLED] mutant writes the next state back into the input grid: '      nextGenerationRow.push(cellIsAlive ? 1 : 0)\n' -> '      nextGenerationRow.push(cellIsAlive ? 1 : 0)\n      if (i > 0) cells[i - 1][j] = nextGeneration[i - 1][j]\n'
       failed:  newGeneration should produce the next generation according to the rules
       failed:  newGeneration is deterministic and isolates its input ordinary input: one glider step
       failed:  newGeneration is deterministic and isolates its input does not modify the input grid
       failed:  newGeneration is deterministic and isolates its input accepts a deeply frozen grid, so it never writes to its input
       failed:  newGeneration is deterministic and isolates its input same input twice in fresh state gives the same result
       failed:  newGeneration is deterministic and isolates its input an earlier call with another input cannot change a later result

focused tests: 9/9 passed  (node_modules/.bin/vitest run Cellular-Automata/test/ConwaysGameOfLife.test.js --reporter=json --outputFile=work/R50-T005/vitest-focused.raw.json)
npm test:      11978/11978 passed  (npm test -- --reporter=json --outputFile=work/R50-T005/vitest-full.raw.json)

R50-T005: all checks passed
(exit 0)

Testing

Automated check: python3 work/R50-T005/check.py installs 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 in commands.log.

To reproduce:

git fetch https://github.com/stavansomaiya/TheAlgorithms-JavaScript.git student/e26b07f1064/R50-T005
git checkout FETCH_HEAD
python3 work/R50-T005/check.py

Recorded results (committed in results.json; tool versions in versions.txt):

Check Command Result
Install from lockfile npm ci --ignore-scripts --no-audit --no-fund ✅ exit 0
Focused tests vitest run Cellular-Automata/test/ConwaysGameOfLife.test.js ✅ 9/9 passed
Fixture evidence (input / expected / actual / source line) node work/R50-T005/evidence.mjs ✅ 9/9 rows match
Mutant (temporary copy): writes the next state back into the input grid applied by check.py ✅ caught by does not modify the input grid
Repository test script, non-watch npm test (vitest run) ✅ 11978/11978 passed
Code style npm run check-style (Prettier) ✅ passes
Spelling (CI settings) codespell ✅ no new findings

Acceptance criteria → evidence:

# Done when (quoted from #5) Evidence in this PR
1 The checked behavior is tied to newGeneration in Cellular-Automata/ConwaysGameOfLife.js; every assertion has an explicit expected value. ✅ Every test compares with a literal grid: [], [[0]], the hand-computed 5×5 glider step and [[1, 1], [1, 1]].
2 Use the smallest valid input and one ordinary input for newGeneration from Cellular-Automata/ConwaysGameOfLife.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. ✅ Smallest [] → [] (and [[1]] → [[0]]). Ordinary: one glider step, worked out cell by cell from rules 1–3 (lines 4–6). Preconditions cite source lines: new arrays at lines 25 and 27, input only read at line 43, result returned at line 53.
3 Existing supported behavior and the public interface are preserved unless a failing regression demonstrates and documents a defect. ✅ No logic change (JSDoc only). The existing test passes, and the full suite passes (11978/11978).
4 The focused test works without live network access, a real user account or GUI interaction. ✅ Plain Node + Vitest; no network, account or GUI. Repeatability: same input twice in fresh state gives the same result and an earlier call with another input cannot change a later result. evidence.mjs scans the real source and finds no time, randomness, I/O, global or import dependency.
5 Any introduced dependency parameter has a default preserving current callers. ✅ No dependency parameter was introduced. The function is already pure (the source scan above is the evidence), so existing callers are unaffected.

Evidence files: check.py · README.md (contract, fixture, baseline, findings) · evidence.mjs · results.json · vitest-focused.json

Checklist

  • I have tested my changes locally.
  • I have added or updated tests, if needed.
  • I have updated documentation, if needed.
  • I have followed the project's coding guidelines.
  • I have run the relevant tests and checks.
  • I have addressed previous review feedback, if applicable. (No review feedback yet.)

Additional Notes

All checks run in plain Node/Vitest, with no network, user account or GUI. Sensitivity check: a temporary copy that writes the computed state back into cells fails does not modify the input grid. Negative control for the dependency scan: adding Math.random() to a copy makes the scan report ["Math"].

Scope: the PR changes only Cellular-Automata/ConwaysGameOfLife.js, its test file and work/R50-T005/. work/R50-T005/ is coursework evidence and would be removed from any later upstream PR.

All 10 tasks (one PR each)
Task Issue Branch Pull request
R50-T001: Lock down the contract of setBit #1 R50-T001 #99
R50-T002: Define the supported boundaries of checkKeywordValidity #2 R50-T002 #100
R50-T003: Cross-check getParentPosition #3 R50-T003 #101
R50-T004: Test an invariant of swap #4 R50-T004 #102
R50-T005: Make verification repeatable for newGeneration #5 R50-T005 #103 (this PR)
R50-T006: Simplify one responsibility in countLetters #6 R50-T006 #104
R50-T007: Publish a runnable example for DisjointSetTreeNode #7 R50-T007 #105
R50-T008: Cover the failure behavior of TrieNode #8 R50-T008 #106
R50-T009: Measure the work done by fibonacci #9 R50-T009 #107
R50-T010: Strengthen the tests of OpenKnightTour #10 R50-T010 #108

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

Successfully merging this pull request may close these issues.

Stavan Somaiya — R50-T005: Make verification repeatable for newGeneration (ConwaysGameOfLife.js) [Cellular-Automata/ConwaysGameOfLife.js]

1 participant