:::bash
Call me Ishmael.
:::bash
"you haint no objections to sharing a harpooneer's blanket,
have ye? I s'pose you are goin' a-whalin',
so you'd better get used to that sort of thing."
The function count_words()
in the module word_counter.py calculates the number of words in a text body.
For instance, we would expect the following input to result in a word count of 3
:
:::bash
Call me Ishmael
Your task is to prove that the count_words()
function in fact returns 3
.
Run the example test in test_unit_test.py
with
:::bash
pytest test_unit_test.py
Run the tests in test_broken.py
and inspect the output.
One of the tests fails, because there is a bug in the function count_words()
.
The other test fails because there is a bug in the test.
Find out what is broken in which test.
Fix the code and test in test_broken.py
.
Run the tests again, so that both of them pass.
High quality tests cover many different situations. Common situations for the program word_counter.py include:
test case | description | example input | expected output |
---|---|---|---|
empty | input is valid, but empty | "" | 0 |
minimal | smallest reasonable input | "whale" | 1 |
typical | representative input | "whale eats captain" | 3 |
invalid | input is supposed to fail | 777 | TypeError |
maximum | largest reasonable input | Melville's entire book | > 200000 |
nasty | difficult example | "That #~&%* program still doesn't work!" | 6 |
Your task is to make all tests in test_border_cases.py pass.
Add a new feature to the word_counter.py program. The program should remove special characters from the text before counting words.
Your task is to write a test for this new feature.