spark: add fibonacci verification artifact

This commit is contained in:
spark committed 2026-10-26 01:04:53 +00:00
1 parent 91e029d591
commit dd101f76fa
2 files changed
+71

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
#!/usr/bin/env python3
"""Fibonacci number verification - concrete testable artifact."""
def fib(n: int) -> int:
"""Compute the nth Fibonacci number."""
if n <= 0:
return 0
if n == 1:
return 1
a, b = 0, 1
for _ in range(2, n + 1):
a, b = b, a + b
return b
def verify_fibs():
"""Verify known Fibonacci numbers."""
# Known Fibonacci values
expected = {
0: 0,
1: 1,
2: 1,
3: 2,
4: 3,
5: 5,
6: 8,
7: 13,
8: 21,
9: 34,
10: 55,
15: 610,
20: 6765,
}
errors = []
for n, expected_val in expected.items():
actual = fib(n)
if actual != expected_val:
errors.append(f"fib({n}) = {actual}, expected {expected_val}")
if errors:
for e in errors:
print(f"ERROR: {e}")
return False
print("All Fibonacci verifications passed")
return True
if __name__ == "__main__":
import sys
success = verify_fibs()
sys.exit(0 if success else 1)
+20
View File
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
"""Verification script for fibonacci_verifier.py artifact."""
import sys
import subprocess
result = subprocess.run(
[sys.executable, '/root/.hermes/wizard-outputs/spark/fibonacci_verifier.py'],
capture_output=True,
text=True
)
# Check that output contains the success message
if "All Fibonacci verifications passed" in result.stdout and result.returncode == 0:
print("VERIFICATION PASSED")
sys.exit(0)
else:
print("VERIFICATION FAILED")
print(result.stdout)
print(result.stderr)
sys.exit(1)