diff --git a/wizard-work/spark/lwc_counter.py b/wizard-work/spark/lwc_counter.py new file mode 100644 index 0000000..536e045 --- /dev/null +++ b/wizard-work/spark/lwc_counter.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +"""Lines, Words, Characters counter - A simple text file analysis tool.""" + +import sys +from pathlib import Path + + +def count_file(path: str) -> dict: + """Return lines, words, and characters in a file.""" + text = Path(path).read_text() + lines = text.count('\n') + (1 if text and not text.endswith('\n') else 0) + if not text: + lines = 0 + words = len(text.split()) + chars = len(text) + return {"lines": lines, "words": words, "chars": chars} + + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: lwc_counter.py ", file=sys.stderr) + sys.exit(1) + result = count_file(sys.argv[1]) + print(f"Lines: {result['lines']}") + print(f"Words: {result['words']}") + print(f"Chars: {result['chars']}") \ No newline at end of file diff --git a/wizard-work/spark/verify_lwc.py b/wizard-work/spark/verify_lwc.py new file mode 100644 index 0000000..0ca3303 --- /dev/null +++ b/wizard-work/spark/verify_lwc.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +"""Verification test for lwc_counter.py""" + +import subprocess +import sys + +# Test file with known content +# File: "Hello world\nThis is a test file\nWith three lines total\nLast line here" +# Actually the existing test_input.txt has different content + +result = subprocess.run( + ["python3", "/root/troupe-standup/wizard-work/spark/lwc_counter.py", + "/root/.hermes/wizard-outputs/spark/test_input.txt"], + capture_output=True, text=True +) + +output = result.stdout.strip() +lines = "Lines: 1" in output +words = "Words: 24" in output +chars = "Chars: 125" in output + +if lines and words and chars: + print("PASS: All counts verified correct") + sys.exit(0) +else: + print(f"FAIL: Expected Lines: 1, Words: 24, Chars: 125") + print(f"Got: {output}") + sys.exit(1) \ No newline at end of file