From da1c267bb75b67f68868c905591bf7b42daea1d1 Mon Sep 17 00:00:00 2001 From: Stavan Somaiya Date: Mon, 23 Nov 2026 10:19:48 +0530 Subject: [PATCH] docs(FibonacciNumberRecursive): state measured complexity and add indexing regression (R50-T009) Fixes: #9 --- Recursive/FibonacciNumberRecursive.js | 10 + .../test/FibonacciNumberRecursive.test.js | 15 + work/R50-T009/README.md | 96 +++++++ work/R50-T009/check.py | 267 ++++++++++++++++++ work/R50-T009/commands.log | 16 ++ work/R50-T009/evidence.mjs | 119 ++++++++ work/R50-T009/results.json | 128 +++++++++ work/R50-T009/task.json | 14 + work/R50-T009/timings.json | 45 +++ work/R50-T009/versions.txt | 5 + work/R50-T009/vitest-focused.json | 44 +++ 11 files changed, 759 insertions(+) create mode 100644 work/R50-T009/README.md create mode 100644 work/R50-T009/check.py create mode 100644 work/R50-T009/commands.log create mode 100644 work/R50-T009/evidence.mjs create mode 100644 work/R50-T009/results.json create mode 100644 work/R50-T009/task.json create mode 100644 work/R50-T009/timings.json create mode 100644 work/R50-T009/versions.txt create mode 100644 work/R50-T009/vitest-focused.json diff --git a/Recursive/FibonacciNumberRecursive.js b/Recursive/FibonacciNumberRecursive.js index 911d078e91..7a873a6ca7 100644 --- a/Recursive/FibonacciNumberRecursive.js +++ b/Recursive/FibonacciNumberRecursive.js @@ -4,6 +4,16 @@ * @param {Integer} n - The input integer * @return {Integer} - Return the N-th Fibonacci number * @see [Fibonacci](https://en.wikipedia.org/wiki/Fibonacci_number) + * + * Indexing is zero-based: fibonacci(0) = 0, fibonacci(1) = 1, fibonacci(10) = 55. + * + * Complexity, with input size n = the index passed in (not its bit length): + * - Calls: exactly C(n) = 2 * F(n + 1) - 1, because C(0) = C(1) = 1 and + * C(n) = 1 + C(n - 1) + C(n - 2). So time is Theta(phi^n), phi ~ 1.618; + * each step of 4 in n multiplies the work by about phi^4 ~ 6.85. + * The function is deterministic, so this is both the worst and every case. + * - Space: O(n) for the recursion stack (deepest chain n, n-1, ..., 1). + * An experiment counting calls for n = 20, 24, 28 matched C(n) exactly. */ const fibonacci = (n) => { diff --git a/Recursive/test/FibonacciNumberRecursive.test.js b/Recursive/test/FibonacciNumberRecursive.test.js index fbb67ac84f..ee28d104cc 100644 --- a/Recursive/test/FibonacciNumberRecursive.test.js +++ b/Recursive/test/FibonacciNumberRecursive.test.js @@ -17,3 +17,18 @@ describe('FibonacciNumberRecursive', () => { expect(fibonacci(9)).toBe(34) }) }) + +// Regression for the zero-based indexing stated in the JSDoc of fibonacci +// (FibonacciNumberRecursive.js line 8). Expected values from the definition +// F(0) = 0, F(1) = 1, F(n) = F(n - 1) + F(n - 2). +describe('FibonacciNumberRecursive indexing', () => { + it.each([ + [0, 0], + [1, 1], + [2, 1], + [5, 5], + [10, 55] + ])('fibonacci(%i) is %i', (n, expected) => { + expect(fibonacci(n)).toBe(expected) + }) +}) diff --git a/work/R50-T009/README.md b/work/R50-T009/README.md new file mode 100644 index 0000000000..c0b170a4d9 --- /dev/null +++ b/work/R50-T009/README.md @@ -0,0 +1,96 @@ +# R50-T009 — Measuring the work done by recursive `fibonacci` + +Source: `Recursive/FibonacciNumberRecursive.js`, `fibonacci` (line 19 after this change; line 9 at pinned commit `5c39e87`). + +## Recorded contract (before any change) + +| Aspect | Observation | +| --------------------- | ------------------------------------------------------------------------------------- | +| Input | `n`, a non-negative integer index. Zero-based: `F(0) = 0`, `F(1) = 1`. | +| Result | `n` when `n < 2` (lines 20-21), else `fibonacci(n - 2) + fibonacci(n - 1)` (line 23). | +| Mutation | none. | +| External dependencies | none. | + +## Fixture (zero-based, as the source defines) + +| n | expected | actual | +| --- | -------- | ------ | +| 0 | 0 | 0 | +| 1 | 1 | 1 | +| 2 | 1 | 1 | +| 5 | 5 | 5 | +| 10 | 55 | 55 | + +Baseline: these values were written down before running the code and matched the unmodified +implementation. The only source change is documentation, so behaviour is unchanged. + +## Complexity claim (now in the JSDoc) + +Input size variable: **n, the index** (not the number of bits of n). + +- Calls: `C(0) = C(1) = 1`, `C(n) = 1 + C(n - 1) + C(n - 2)`, which solves to exactly + `C(n) = 2·F(n + 1) − 1`. Time is therefore Θ(φⁿ), φ ≈ 1.618. The function is deterministic, so + this is the worst case and every case. +- Space: O(n) recursion depth. + +This is a proof-based claim. The experiment below is an **observation** that agrees with it. + +## Experiment + +- Sizes n = 20, 24, 28 (each +4 should multiply the work by φ⁴ ≈ 6.854). Short, CPU-only run. +- Operation count: calls, counted in an in-memory copy of the real source with a counter added at + the top of the function body (the file on disk is not changed). +- Timing: the real function, `performance.now()` around the call only, after a warm-up call, 5 + repetitions per size; median and range reported. Process startup, module loading, I/O and JIT + compilation are outside the timed interval. Inputs are fixed integers, so no random seed is needed; + each repetition is a fresh call with no cache. +- Every result is checked against an independent iterative implementation **outside** the timed + interval. + +Results from the run committed here (`timings.json`; timings vary by machine and are rewritten on +each run): + +| n | calls (measured) | 2·F(n+1) − 1 | median ms | range ms | +| --- | ---------------- | ------------ | --------- | ------------- | +| 20 | 21,891 | 21,891 | 0.042 | 0.042 – 0.096 | +| 24 | 150,049 | 150,049 | 0.253 | 0.248 – 0.255 | +| 28 | 1,028,457 | 1,028,457 | 1.734 | 1.73 – 1.739 | + +Call ratio between consecutive sizes: **6.854** both times (= φ⁴). Median time ratios: 6.02 and 6.85 +— close to φ⁴, with more noise at n = 20 where each call takes well under a millisecond. + +Pass/fail depends only on values and exact call counts, never on wall-clock speed. + +## Sensitivity check (temporary copy only) + +`check.py` widens the base case to `n <= 2` in a temp copy. The named regression `fibonacci(2) is 1` +passes on the original and fails on the copy, which returns 2. The real source is never modified. + +## Code change + +- JSDoc on `fibonacci`: indexing convention and the complexity statement above. +- One representative regression in the normal tests: indices 0, 1, 2, 5, 10 → 0, 1, 1, 5, 55. + +## How to run + +From the repository root: + +```sh +python3 work/R50-T009/check.py +``` + +`check.py` installs dependencies from `package-lock.json`, runs the focused test file, evaluates the fixture with `evidence.mjs` (input, expected, actual and source line for every case), runs each deliberate mutant in a temporary copy, and finally runs the repository test script in non-watch mode (`npm test`, which is `vitest run`). It exits non-zero if any assertion or step fails, and records every command it ran in `commands.log`. + +### Recorded run (files in this folder) + +| Step | Command | Result | +| ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- | +| Install from lockfile | `npm ci --ignore-scripts --no-audit --no-fund` (exit 0) | ok | +| Focused tests | `node_modules/.bin/vitest run Recursive/test/FibonacciNumberRecursive.test.js --reporter=json --outputFile=work/R50-T009/vitest-focused.raw.json` | 9/9 passed | +| Fixture evidence | `node work/R50-T009/evidence.mjs` | 8/8 rows match | +| Mutant: base case widened (n < 2 becomes n <= 2) | temporary copy | killed by `fibonacci(2) is 1` | +| Repository test script | `npm test -- --reporter=json --outputFile=work/R50-T009/vitest-full.raw.json` | 11975/11975 passed | + +Tool versions (`versions.txt`): python 3.12.10; node v26.13.1; npm 11.20.0; platform macOS-27.2.1-arm64-arm-64bit; vitest vitest/1.2.1 darwin-arm64 node-v26.13.1. + +Files: `results.json` (all of the above, machine-readable), `vitest-focused.json` (each focused test and its status), `commands.log`, `versions.txt`. diff --git a/work/R50-T009/check.py b/work/R50-T009/check.py new file mode 100644 index 0000000000..f94cffac53 --- /dev/null +++ b/work/R50-T009/check.py @@ -0,0 +1,267 @@ +#!/usr/bin/env python3 +"""Focused check runner for R50-T009. + +Run from the repository root: + + python3 work/R50-T009/check.py + +Steps (everything is recorded under work/R50-T009/): + 1. Record tool versions -> versions.txt + 2. Install dependencies from the lockfile -> `npm ci --ignore-scripts` + (set SKIP_INSTALL=1 to reuse an existing node_modules) + 3. Run the focused Vitest file(s) for this task; require a non-zero test + count and zero failures -> vitest-focused.json + 4. Run evidence.mjs: literal fixture inputs against the real source, with + input / expected / actual / source line -> results.json ("fixture") + 5. Run each deliberate mutant in a temporary copy (never in the real + source); require the named regression test to pass on the original and + fail on the mutant -> results.json ("mutants") + 6. Run the repository test script in non-watch mode + (`npm test` = `vitest run`); require a non-zero test count and zero + failures -> results.json ("full_suite") + +Every command actually executed is written to commands.log. The exit status +is non-zero if any step or assertion fails (or a step times out). +""" + +import json +import os +import platform +import shutil +import subprocess +import sys +import tempfile +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parent.parent +CONFIG = json.loads((HERE / 'task.json').read_text()) +TASK = CONFIG['task'] +VITEST = str(ROOT / 'node_modules' / '.bin' / 'vitest') +TIMEOUT_SECONDS = 600 + +failures = [] +log = [] + + +def show(text): + """Hide machine-specific absolute paths in recorded evidence.""" + text = text.replace(str(ROOT) + os.sep, '').replace(str(ROOT), '.') + return text.replace(tempfile.gettempdir(), '$TMPDIR') + + +def run(cmd, cwd=ROOT, check=False): + """Run a command, log it exactly, and never wait forever.""" + shown = show(' '.join(cmd)) + log.append('$ ' + shown) + try: + proc = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True, + timeout=TIMEOUT_SECONDS) + except subprocess.TimeoutExpired: + log.append(f' -> timed out after {TIMEOUT_SECONDS}s') + failures.append(f'timed out: {shown}') + return subprocess.CompletedProcess(cmd, 124, '', 'timeout') + log.append(f' -> exit {proc.returncode}') + if check and proc.returncode != 0: + print(proc.stdout[-4000:]) + print(proc.stderr[-4000:], file=sys.stderr) + return proc + + +def version(cmd): + try: + return run(cmd).stdout.strip().splitlines()[0] + except Exception as exc: # best effort only + return f'unavailable ({exc})' + + +def test_list(report): + return [ + {'name': t.get('fullName') or t.get('title'), 'status': t.get('status')} + for suite in report.get('testResults', []) + for t in suite.get('assertionResults', []) + ] + + +def read_report(proc, out): + if not out.exists(): + print(proc.stdout[-4000:]) + print(proc.stderr[-4000:], file=sys.stderr) + return None + report = json.loads(out.read_text()) + out.unlink() + return report + + +def summary(cmd, proc, report): + return { + 'command': show(' '.join(cmd)), + 'exit': proc.returncode, + 'total': report and report['numTotalTests'], + 'passed': report and report['numPassedTests'], + 'failed': report and report['numFailedTests'] + } + + +def require_green(label, info, report): + if info['exit'] != 0 or not report or report['numTotalTests'] == 0 or \ + report['numFailedTests'] != 0: + failures.append(f'{label} failed: {info}') + if report: + failures.extend(' failed: ' + t['name'] + for t in test_list(report) + if t['status'] == 'failed') + + +def main(): + results = {'task': TASK} + + # 1. Tool versions + versions = { + 'python': platform.python_version(), + 'node': version(['node', '--version']), + 'npm': version(['npm', '--version']), + 'platform': platform.platform() + } + + # 2. Install from the lockfile + if os.environ.get('SKIP_INSTALL') == '1': + results['install'] = 'skipped (SKIP_INSTALL=1)' + else: + cmd = ['npm', 'ci', '--ignore-scripts', '--no-audit', '--no-fund'] + proc = run(cmd, check=True) + results['install'] = {'command': ' '.join(cmd), + 'exit': proc.returncode} + if proc.returncode != 0: + failures.append('npm ci failed') + return finish(results, versions) + versions['vitest'] = version([VITEST, '--version']) + + # 3. Focused tests + out = HERE / 'vitest-focused.raw.json' + cmd = [VITEST, 'run', *CONFIG['focused_tests'], '--reporter=json', + f'--outputFile={out}'] + proc = run(cmd) + focused_report = read_report(proc, out) + results['focused_tests'] = summary(cmd, proc, focused_report) + require_green('focused tests', results['focused_tests'], focused_report) + if focused_report: + (HERE / 'vitest-focused.json').write_text(json.dumps({ + 'command': results['focused_tests']['command'], + 'numTotalTests': focused_report['numTotalTests'], + 'numPassedTests': focused_report['numPassedTests'], + 'numFailedTests': focused_report['numFailedTests'], + 'tests': test_list(focused_report) + }, indent=2) + '\n') + + # 4. Fixture evidence (input / expected / actual / source line) + proc = run(['node', str(HERE / 'evidence.mjs')]) + rows = [] + if proc.returncode != 0: + failures.append('evidence.mjs crashed: ' + show(proc.stderr[-2000:])) + else: + rows = json.loads(proc.stdout) + results['fixture'] = rows + for row in rows: + print(f"[{'PASS' if row['pass'] else 'FAIL'}] {row['name']}") + print(f" input: {json.dumps(row['input'])}") + print(f" expected: {json.dumps(row['expected'])}") + print(f" actual: {json.dumps(row['actual'])}") + if row.get('precondition'): + print(f" source: {row['precondition']}") + if not row['pass']: + failures.append(f"fixture mismatch: {row['name']}") + if not rows: + failures.append('no fixture rows were produced') + + # 5. Deliberate mutants, in temporary copies only + original_tests = test_list(focused_report) if focused_report else [] + mutants = [run_mutant(m, original_tests) for m in CONFIG.get('mutants', [])] + if mutants: + results['mutants'] = mutants + + # 6. Repository test script in non-watch mode: `npm test` (vitest run) + out = HERE / 'vitest-full.raw.json' + cmd = ['npm', 'test', '--', '--reporter=json', f'--outputFile={out}'] + proc = run(cmd) + full_report = read_report(proc, out) + results['full_suite'] = summary(cmd, proc, full_report) + require_green('repository test script', results['full_suite'], full_report) + + return finish(results, versions) + + +def run_mutant(mutant, original_tests): + """Copy the source and its tests into a temp dir, apply one edit there, + and require the named test to pass on the original and fail here.""" + original = (ROOT / mutant['file']).read_text() + named = [t for t in original_tests if mutant['must_fail'] in t['name']] + entry = { + 'name': mutant['name'], + 'file': mutant['file'], + 'edit': {'from': mutant['find'], 'to': mutant['replace']}, + 'named_test': mutant['must_fail'], + 'named_test_on_original': [t['status'] for t in named], + 'killed': False + } + if len(named) != 1 or named[0]['status'] != 'passed': + failures.append(f"mutant {mutant['name']}: named test must match " + f"exactly one passing test on the original") + return entry + if original.count(mutant['find']) != 1: + failures.append(f"mutant {mutant['name']}: edit must match once") + return entry + with tempfile.TemporaryDirectory(prefix=f'{TASK}-mutant-') as tmp: + tmp = Path(tmp) + for rel in [mutant['file'], *mutant['tests']]: + dest = tmp / rel + dest.parent.mkdir(parents=True, exist_ok=True) + shutil.copy(ROOT / rel, dest) + (tmp / mutant['file']).write_text( + original.replace(mutant['find'], mutant['replace'])) + out = tmp / 'mutant-report.json' + cmd = [VITEST, 'run', *mutant['tests'], '--root', str(tmp), + '--globals', '--reporter=json', f'--outputFile={out}'] + proc = run(cmd) + report = read_report(proc, out) + failed = [t['name'] for t in test_list(report) + if t['status'] == 'failed'] if report else [] + entry['exit'] = proc.returncode + entry['failed_tests_on_mutant'] = failed + entry['killed'] = proc.returncode != 0 and any( + mutant['must_fail'] in name for name in failed) + print(f"[{'KILLED' if entry['killed'] else 'SURVIVED'}] mutant " + f"{mutant['name']}: {mutant['find']!r} -> {mutant['replace']!r}") + for name in failed: + print(f' failed: {name}') + if not entry['killed']: + failures.append(f"mutant {mutant['name']} was not detected by " + f"'{mutant['must_fail']}'") + return entry + + +def finish(results, versions): + results['ok'] = not failures + results['failures'] = failures + (HERE / 'versions.txt').write_text( + ''.join(f'{k}: {v}\n' for k, v in versions.items())) + (HERE / 'results.json').write_text(json.dumps(results, indent=2) + '\n') + (HERE / 'commands.log').write_text('\n'.join(log) + '\n') + print() + for key, label in [('focused_tests', 'focused tests'), + ('full_suite', 'npm test')]: + if key in results: + info = results[key] + print(f"{label + ':':15}{info['passed']}/{info['total']} passed" + f" ({info['command']})") + if failures: + print('\nFAILED:') + for item in failures: + print(' - ' + item) + return 1 + print(f'\n{TASK}: all checks passed') + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/work/R50-T009/commands.log b/work/R50-T009/commands.log new file mode 100644 index 0000000000..cc9017be78 --- /dev/null +++ b/work/R50-T009/commands.log @@ -0,0 +1,16 @@ +$ node --version + -> exit 0 +$ npm --version + -> exit 0 +$ npm ci --ignore-scripts --no-audit --no-fund + -> exit 0 +$ node_modules/.bin/vitest --version + -> exit 0 +$ node_modules/.bin/vitest run Recursive/test/FibonacciNumberRecursive.test.js --reporter=json --outputFile=work/R50-T009/vitest-focused.raw.json + -> exit 0 +$ node work/R50-T009/evidence.mjs + -> exit 0 +$ node_modules/.bin/vitest run Recursive/test/FibonacciNumberRecursive.test.js --root $TMPDIR/R50-T009-mutant-dx_s8qnx --globals --reporter=json --outputFile=$TMPDIR/R50-T009-mutant-dx_s8qnx/mutant-report.json + -> exit 1 +$ npm test -- --reporter=json --outputFile=work/R50-T009/vitest-full.raw.json + -> exit 0 diff --git a/work/R50-T009/evidence.mjs b/work/R50-T009/evidence.mjs new file mode 100644 index 0000000000..2d89c5932c --- /dev/null +++ b/work/R50-T009/evidence.mjs @@ -0,0 +1,119 @@ +// R50-T009 evidence: correctness fixture, exact call counts, and timings for +// the recursive fibonacci. Prints JSON rows; also writes timings.json. +// +// - Input size: n, the index passed to fibonacci. +// - Operation count: number of calls. Counted in an in-memory copy of the +// real source with a counter added on the first line of the function body; +// the source file itself is not changed. +// - Timings: performance.now() around the call only (after a warm-up call), +// so process startup, module loading, I/O and JIT compilation are outside +// the timed interval. No pass/fail decision uses a timing. +import { readFileSync, writeFileSync } from 'fs' +import { performance } from 'perf_hooks' +import { fibonacci } from '../../Recursive/FibonacciNumberRecursive.js' + +const SRC = 'FibonacciNumberRecursive.js' +const here = new URL('.', import.meta.url) + +// Independent oracle: iterative, O(n), does not call fibonacci. +const iterative = (n) => { + let [a, b] = [0, 1] + for (let i = 0; i < n; i++) [a, b] = [b, a + b] + return a +} + +const rows = [ + [0, 0], + [1, 1], + [2, 1], + [5, 5], + [10, 55] +].map(([n, expected]) => { + const actual = fibonacci(n) + return { + name: `fibonacci(${n})`, + input: n, + expected, + actual, + pass: actual === expected, + precondition: `${SRC}:8 zero-based indexing; :20-21 base case n < 2` + } +}) + +// Instrumented copy for call counting. +const source = readFileSync( + new URL('../../Recursive/FibonacciNumberRecursive.js', import.meta.url), + 'utf8' +) +const marker = 'const fibonacci = (n) => {' +if (!source.includes(marker)) throw new Error('function header not found') +const instrumented = + 'let calls = 0\nconst resetCalls = () => { calls = 0 }\nconst getCalls = () => calls\n' + + source.replace(marker, `${marker}\n calls++`) + + '\nexport { resetCalls, getCalls }\n' +const counted = await import( + 'data:text/javascript,' + encodeURIComponent(instrumented) +) + +const sizes = [20, 24, 28] +const REPS = 5 +const experiment = [] +for (const n of sizes) { + // Exact call count (deterministic). + counted.resetCalls() + counted.fibonacci(n) + const calls = counted.getCalls() + const predictedCalls = 2 * iterative(n + 1) - 1 + + // Timings of the real, uninstrumented function. + fibonacci(n) // warm-up so compilation is not timed + const times = [] + const results = [] + for (let r = 0; r < REPS; r++) { + const t0 = performance.now() + const value = fibonacci(n) + times.push(performance.now() - t0) + results.push(value) // checked below, outside the timed interval + } + const sorted = [...times].sort((a, b) => a - b) + const expectedValue = iterative(n) + experiment.push({ + n, + calls, + predictedCalls, + medianMs: +sorted[2].toFixed(3), + rangeMs: [+sorted[0].toFixed(3), +sorted[REPS - 1].toFixed(3)], + allResultsCorrect: results.every((v) => v === expectedValue) + }) + rows.push({ + name: `n = ${n}: value and exact call count`, + input: n, + expected: { value: expectedValue, calls: predictedCalls }, + actual: { value: results[0], calls }, + pass: results.every((v) => v === expectedValue) && calls === predictedCalls, + precondition: `${SRC}:23 two recursive calls per n >= 2` + }) +} + +const ratios = experiment.slice(1).map((e, i) => ({ + from: experiment[i].n, + to: e.n, + callRatio: +(e.calls / experiment[i].calls).toFixed(3), + medianTimeRatio: +(e.medianMs / experiment[i].medianMs).toFixed(2) +})) +writeFileSync( + new URL('timings.json', here), + JSON.stringify( + { + note: 'Observations only; no threshold is applied to timings.', + phiToThe4th: +(((1 + Math.sqrt(5)) / 2) ** 4).toFixed(3), + repetitions: REPS, + experiment, + ratios + }, + null, + 2 + ) + '\n' +) + +console.log(JSON.stringify(rows)) diff --git a/work/R50-T009/results.json b/work/R50-T009/results.json new file mode 100644 index 0000000000..edb6f9426a --- /dev/null +++ b/work/R50-T009/results.json @@ -0,0 +1,128 @@ +{ + "task": "R50-T009", + "install": { + "command": "npm ci --ignore-scripts --no-audit --no-fund", + "exit": 0 + }, + "focused_tests": { + "command": "node_modules/.bin/vitest run Recursive/test/FibonacciNumberRecursive.test.js --reporter=json --outputFile=work/R50-T009/vitest-focused.raw.json", + "exit": 0, + "total": 9, + "passed": 9, + "failed": 0 + }, + "fixture": [ + { + "name": "fibonacci(0)", + "input": 0, + "expected": 0, + "actual": 0, + "pass": true, + "precondition": "FibonacciNumberRecursive.js:8 zero-based indexing; :20-21 base case n < 2" + }, + { + "name": "fibonacci(1)", + "input": 1, + "expected": 1, + "actual": 1, + "pass": true, + "precondition": "FibonacciNumberRecursive.js:8 zero-based indexing; :20-21 base case n < 2" + }, + { + "name": "fibonacci(2)", + "input": 2, + "expected": 1, + "actual": 1, + "pass": true, + "precondition": "FibonacciNumberRecursive.js:8 zero-based indexing; :20-21 base case n < 2" + }, + { + "name": "fibonacci(5)", + "input": 5, + "expected": 5, + "actual": 5, + "pass": true, + "precondition": "FibonacciNumberRecursive.js:8 zero-based indexing; :20-21 base case n < 2" + }, + { + "name": "fibonacci(10)", + "input": 10, + "expected": 55, + "actual": 55, + "pass": true, + "precondition": "FibonacciNumberRecursive.js:8 zero-based indexing; :20-21 base case n < 2" + }, + { + "name": "n = 20: value and exact call count", + "input": 20, + "expected": { + "value": 6765, + "calls": 21891 + }, + "actual": { + "value": 6765, + "calls": 21891 + }, + "pass": true, + "precondition": "FibonacciNumberRecursive.js:23 two recursive calls per n >= 2" + }, + { + "name": "n = 24: value and exact call count", + "input": 24, + "expected": { + "value": 46368, + "calls": 150049 + }, + "actual": { + "value": 46368, + "calls": 150049 + }, + "pass": true, + "precondition": "FibonacciNumberRecursive.js:23 two recursive calls per n >= 2" + }, + { + "name": "n = 28: value and exact call count", + "input": 28, + "expected": { + "value": 317811, + "calls": 1028457 + }, + "actual": { + "value": 317811, + "calls": 1028457 + }, + "pass": true, + "precondition": "FibonacciNumberRecursive.js:23 two recursive calls per n >= 2" + } + ], + "mutants": [ + { + "name": "base case widened (n < 2 becomes n <= 2)", + "file": "Recursive/FibonacciNumberRecursive.js", + "edit": { + "from": " if (n < 2) {\n", + "to": " if (n <= 2) {\n" + }, + "named_test": "fibonacci(2) is 1", + "named_test_on_original": ["passed"], + "killed": true, + "exit": 1, + "failed_tests_on_mutant": [ + " FibonacciNumberRecursive should return 5", + " FibonacciNumberRecursive should return 9", + " FibonacciNumberRecursive indexing fibonacci(2) is 1", + " FibonacciNumberRecursive indexing fibonacci(5) is 5", + " FibonacciNumberRecursive indexing fibonacci(10) is 55" + ] + } + ], + "full_suite": { + "command": "npm test -- --reporter=json --outputFile=work/R50-T009/vitest-full.raw.json", + "exit": 0, + "total": 11975, + "passed": 11975, + "failed": 0 + }, + "ok": true, + "failures": [] +} diff --git a/work/R50-T009/task.json b/work/R50-T009/task.json new file mode 100644 index 0000000000..1e0d006425 --- /dev/null +++ b/work/R50-T009/task.json @@ -0,0 +1,14 @@ +{ + "task": "R50-T009", + "focused_tests": ["Recursive/test/FibonacciNumberRecursive.test.js"], + "mutants": [ + { + "name": "base case widened (n < 2 becomes n <= 2)", + "file": "Recursive/FibonacciNumberRecursive.js", + "find": " if (n < 2) {\n", + "replace": " if (n <= 2) {\n", + "tests": ["Recursive/test/FibonacciNumberRecursive.test.js"], + "must_fail": "fibonacci(2) is 1" + } + ] +} diff --git a/work/R50-T009/timings.json b/work/R50-T009/timings.json new file mode 100644 index 0000000000..8adf6fa42f --- /dev/null +++ b/work/R50-T009/timings.json @@ -0,0 +1,45 @@ +{ + "note": "Observations only; no threshold is applied to timings.", + "phiToThe4th": 6.854, + "repetitions": 5, + "experiment": [ + { + "n": 20, + "calls": 21891, + "predictedCalls": 21891, + "medianMs": 0.042, + "rangeMs": [0.042, 0.096], + "allResultsCorrect": true + }, + { + "n": 24, + "calls": 150049, + "predictedCalls": 150049, + "medianMs": 0.253, + "rangeMs": [0.248, 0.255], + "allResultsCorrect": true + }, + { + "n": 28, + "calls": 1028457, + "predictedCalls": 1028457, + "medianMs": 1.734, + "rangeMs": [1.73, 1.739], + "allResultsCorrect": true + } + ], + "ratios": [ + { + "from": 20, + "to": 24, + "callRatio": 6.854, + "medianTimeRatio": 6.02 + }, + { + "from": 24, + "to": 28, + "callRatio": 6.854, + "medianTimeRatio": 6.85 + } + ] +} diff --git a/work/R50-T009/versions.txt b/work/R50-T009/versions.txt new file mode 100644 index 0000000000..b405ff9cb4 --- /dev/null +++ b/work/R50-T009/versions.txt @@ -0,0 +1,5 @@ +python: 3.12.10 +node: v26.13.1 +npm: 11.20.0 +platform: macOS-27.2.1-arm64-arm-64bit +vitest: vitest/1.2.1 darwin-arm64 node-v26.13.1 diff --git a/work/R50-T009/vitest-focused.json b/work/R50-T009/vitest-focused.json new file mode 100644 index 0000000000..1c4fbbfbb9 --- /dev/null +++ b/work/R50-T009/vitest-focused.json @@ -0,0 +1,44 @@ +{ + "command": "node_modules/.bin/vitest run Recursive/test/FibonacciNumberRecursive.test.js --reporter=json --outputFile=work/R50-T009/vitest-focused.raw.json", + "numTotalTests": 9, + "numPassedTests": 9, + "numFailedTests": 0, + "tests": [ + { + "name": " FibonacciNumberRecursive should return 0", + "status": "passed" + }, + { + "name": " FibonacciNumberRecursive should return 1", + "status": "passed" + }, + { + "name": " FibonacciNumberRecursive should return 5", + "status": "passed" + }, + { + "name": " FibonacciNumberRecursive should return 9", + "status": "passed" + }, + { + "name": " FibonacciNumberRecursive indexing fibonacci(0) is 0", + "status": "passed" + }, + { + "name": " FibonacciNumberRecursive indexing fibonacci(1) is 1", + "status": "passed" + }, + { + "name": " FibonacciNumberRecursive indexing fibonacci(2) is 1", + "status": "passed" + }, + { + "name": " FibonacciNumberRecursive indexing fibonacci(5) is 5", + "status": "passed" + }, + { + "name": " FibonacciNumberRecursive indexing fibonacci(10) is 55", + "status": "passed" + } + ] +}