27 lines
554 B
Python
27 lines
554 B
Python
# 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) |