spark: the six files that only graded or documented a retired counter (Q125)
A scan of wizard-work/spark for every remaining reference to the 25 paths retired ina979e63turns up six files, and each exists only to exercise or describe one of them. They are retired here rather than repointed, because a repointed cell would be a new test of the survivor wearing an old tool's name: check.py imported count_words from word_counter.py through a sys.path.insert of the host wizard-outputs path (the Q106/Q98 class) and tested five string cases test_word_counter.py the same five cases against word_counter.py test_wordcount.py ran wordcount.py and compared to `wc -w` verify_snippets.py the lane's "snippet verification", whose one check was word_counter.py's five cases; it printed VERDICT lines from a count, not from a measurement word-counter-README.md documented word-counter.py's interface and a 7-word example, i.e. prose for a file that is gone scratch_word_counter.py a word counter over the host scratch directory that wrote word_count_report.json to a fixed host path What replaces them: wizard-work/spark/test_line_counter.py, whose word cells (word_and_char_counts, and the words_by_unique mutant that must turn it red) pin `line_counter.py --words` on a fixture that is in the tree. check.py's and test_word_counter.py's five string cases are subsumed by the word cell's three tokens with a repeat, which is the case a unique-word counter cannot pass. Not retired, and deliberately: word_count_report.json and the fixtures test_words.txt / test-input.txt / test-empty.txt are data, not tools -- they are outputs of the retired scripts and are left where they were written; and file_counter.py, file-counter.py, count_functions.py, json_key_counter.py, count_verified_skills.py, verify_count.py, passwd_lines.py and generate_stats.py count files, function definitions, JSON keys, skills, /etc/passwd lines or system metrics -- domain counts, not text statistics of an arbitrary file, and answering them with line_counter.py would be a different tool. The boundary is stated in the Q125 record. Running total: 31 files retired acrossa979e63and this commit; the tree atd85cb40holds every one of them.
This commit is contained in:
1 parent
367d66e574
commit
46b6282296
6 files changed
-201
No files matched your search
@@ -1,28 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check that word_counter.py correctly counts words."""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add the wizard-outputs directory to path
|
||||
sys.path.insert(0, '/root/.hermes/wizard-outputs/spark')
|
||||
|
||||
from word_counter import count_words
|
||||
|
||||
# Run tests
|
||||
tests = [
|
||||
("Hello world test", 3),
|
||||
("", 0),
|
||||
(" ", 0),
|
||||
("one", 1),
|
||||
("one two three four five", 5),
|
||||
]
|
||||
|
||||
for text, expected in tests:
|
||||
result = count_words(text)
|
||||
if result != expected:
|
||||
print(f"FAIL: '{text}' -> {result}, expected {expected}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
print("All tests passed!")
|
||||
sys.exit(0)
|
||||
@@ -1,48 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Count words in all text files in the scratch directory and output JSON report."""
|
||||
import os
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
SCRATCH_DIR = "/root/.hermes/profiles/spark/cache/scratch"
|
||||
OUTPUT_FILE = "/root/.hermes/wizard-outputs/spark/word_count_report.json"
|
||||
|
||||
def count_words_in_file(filepath):
|
||||
"""Count words in a file, return 0 if unreadable."""
|
||||
try:
|
||||
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
content = f.read()
|
||||
return len(content.split())
|
||||
except Exception:
|
||||
return 0
|
||||
|
||||
def main():
|
||||
results = []
|
||||
total_words = 0
|
||||
|
||||
scratch_path = Path(SCRATCH_DIR)
|
||||
if scratch_path.exists():
|
||||
for filepath in sorted(scratch_path.iterdir()):
|
||||
if filepath.is_file():
|
||||
word_count = count_words_in_file(filepath)
|
||||
total_words += word_count
|
||||
results.append({
|
||||
"file": filepath.name,
|
||||
"word_count": word_count
|
||||
})
|
||||
|
||||
report = {
|
||||
"scratch_directory": SCRATCH_DIR,
|
||||
"files_processed": len(results),
|
||||
"total_words": total_words,
|
||||
"files": results
|
||||
}
|
||||
|
||||
with open(OUTPUT_FILE, 'w') as f:
|
||||
json.dump(report, f, indent=2)
|
||||
|
||||
print(f"Word count report written to {OUTPUT_FILE}")
|
||||
print(f"Files: {len(results)}, Total words: {total_words}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,27 +0,0 @@
|
||||
# Test verification: word_counter.py works correctly
|
||||
# Run: python3 test_word_counter.py
|
||||
# Exit 0 = pass
|
||||
|
||||
from word_counter import count_words
|
||||
|
||||
# Test cases
|
||||
tests = [
|
||||
("Hello world test", 3),
|
||||
("", 0),
|
||||
(" ", 0),
|
||||
("one", 1),
|
||||
("one two three four five", 5),
|
||||
]
|
||||
|
||||
all_passed = True
|
||||
for text, expected in tests:
|
||||
result = count_words(text)
|
||||
if result != expected:
|
||||
print(f"FAIL: '{text}' -> {result}, expected {expected}")
|
||||
all_passed = False
|
||||
|
||||
if all_passed:
|
||||
print("All tests passed!")
|
||||
exit(0)
|
||||
else:
|
||||
exit(1)
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/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)
|
||||
@@ -1,48 +0,0 @@
|
||||
# Spark Lane Verification Script
|
||||
# Used for snippet-level micro-tasks in the spark lane
|
||||
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
from datetime import datetime, timezone
|
||||
|
||||
def verify_word_counter():
|
||||
"""Verify word_counter.py functions correctly."""
|
||||
sys.path.insert(0, '/root/troupe-standup/wizard-work/spark')
|
||||
from word_counter import count_words
|
||||
|
||||
tests = [
|
||||
("Hello world test", 3),
|
||||
("", 0),
|
||||
(" ", 0),
|
||||
("one", 1),
|
||||
("one two three four five", 5),
|
||||
]
|
||||
|
||||
passed = 0
|
||||
for text, expected in tests:
|
||||
result = count_words(text)
|
||||
if result == expected:
|
||||
passed += 1
|
||||
|
||||
return passed == len(tests), passed, len(tests)
|
||||
|
||||
def main():
|
||||
print("=== SPARK LANE VERIFICATION ===")
|
||||
print(f"Timestamp: {datetime.now(timezone.utc).isoformat()}")
|
||||
print()
|
||||
|
||||
# Run verification
|
||||
success, passed, total = verify_word_counter()
|
||||
|
||||
print(f"word_counter.py: {passed}/{total} tests passed")
|
||||
|
||||
if success:
|
||||
print("\nVERDICT: All snippets verified successfully")
|
||||
sys.exit(0)
|
||||
else:
|
||||
print("\nVERDICT: Some snippets failed verification")
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,21 +0,0 @@
|
||||
# Word Counter
|
||||
|
||||
A simple Python word counter that counts words in a text file.
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
python3 word-counter.py <filepath>
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```bash
|
||||
$ python3 word-counter.py test-input.txt
|
||||
7
|
||||
```
|
||||
|
||||
## Verification
|
||||
|
||||
- 7 words in test-input.txt: PASS
|
||||
- 0 words in test-empty.txt: PASS
|
||||
Reference in new issue
Block a user