spark: add verification test for wordcount.py

This commit is contained in:
spark committed 2026-10-21 10:25:35 +00:00
1 parent 949858814c
commit a989686a81
1 file changed
+29
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env python3
"""Test script to verify wordcount.py matches wc output."""
import subprocess
import json
# Get wordcount.py output
result = subprocess.run(
['python3', 'wordcount.py', 'test_words.txt'],
capture_output=True, text=True
)
wc_result = json.loads(result.stdout)
wordcount_words = wc_result['words']
# Get wc output
wc_output = subprocess.run(
['wc', '-w', 'test_words.txt'],
capture_output=True, text=True
)
wc_words = int(wc_output.stdout.strip().split()[0])
print(f"wordcount.py: {wordcount_words} words")
print(f"wc: {wc_words} words")
if wordcount_words == wc_words:
print("PASS: Outputs match")
exit(0)
else:
print("FAIL: Outputs differ")
exit(1)