Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dynamic-Programming/FastFibonacciNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ const fastFibonacci = (N) => {
return fib(N)[0]
}

export { fastFibonacci }
export { fastFibonacci, fib }
12 changes: 11 additions & 1 deletion Dynamic-Programming/tests/FastFibonacciNumber.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fastFibonacci } from '../FastFibonacciNumber'
import { fastFibonacci, fib } from '../FastFibonacciNumber'

describe('Testing FibonacciNumber', () => {
const errorCases = ['0', '12', true]
Expand All @@ -21,3 +21,13 @@ describe('Testing FibonacciNumber', () => {
expect(fastFibonacci(input)).toBe(expected)
})
})

describe('fib regression contract', () => {
test('fib returns correct [F(n), F(n+1)] tuple pairs', () => {
expect(fib(0)).toEqual([0, 1])
expect(fib(1)).toEqual([1, 1])
expect(fib(2)).toEqual([1, 2])
expect(fib(5)).toEqual([5, 8])
expect(fib(10)).toEqual([55, 89])
})
})
32 changes: 32 additions & 0 deletions work/R50-T021/check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import subprocess
import json
import sys

def run_checks():
work_dir = "work/R50-T021"
os.makedirs(work_dir, exist_ok=True)

# 1. Capture system versions
node_ver = subprocess.check_output(["node", "-v"]).decode().strip()
npm_ver = subprocess.check_output(["npm", "-v"]).decode().strip()
with open(f"{work_dir}/versions.json", "w") as f:
json.dump({"node": node_ver, "npm": npm_ver}, f, indent=2)

# 2. Run Vitest non-interactively
cmd = ["npx", "vitest", "run", "Dynamic-Programming/tests/FastFibonacciNumber.test.js"]
res = subprocess.run(cmd, capture_output=True, text=True)

with open(f"{work_dir}/test_output.log", "w") as f:
f.write(res.stdout + "\n" + res.stderr)

if res.returncode == 0:
with open(f"{work_dir}/fixture_results.json", "w") as f:
json.dump({"status": "PASSED", "task": "R50-T021"}, f, indent=2)
print("All checks passed.")
else:
print("Tests failed!")
sys.exit(1)

if __name__ == "__main__":
run_checks()
4 changes: 4 additions & 0 deletions work/R50-T021/fixture_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"status": "PASSED",
"task": "R50-T021"
}
11 changes: 11 additions & 0 deletions work/R50-T021/test_output.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

 RUN  v5.1.0 /Users/fabulous_tarun8/Library/Mobile Documents/com~apple~CloudDocs/Studies/s&ai/diwaliHomework/TheAlgorithms-JavaScript

✓ Dynamic-Programming/tests/FastFibonacciNumber.test.js (9 tests) 2ms

 Test Files  1 passed (1)
 Tests  9 passed (9)
 Start at  07:55:20
 Duration  83ms (transform 48%, import 21%, worker 17%, tests 13%)


4 changes: 4 additions & 0 deletions work/R50-T021/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"node": "v26.12.1",
"npm": "11.20.0"
}