Write the Tests That Catch the Bug
chunk_document(text, chunk_size, overlap) is already implemented and correct. Write the tests that would catch a bug in it.
Its contract:
- Each chunk holds at most
chunk_sizewords. - Each chunk after the first starts
overlapwords before the previous one ended. - Chunks are strings, words rejoined with single spaces.
- Never an empty chunk, and never a chunk whose words are all already covered by the previous one.
- Empty or whitespace-only input returns
[].
Write functions named test_* that call chunk_document and assert on the result. No return values, no printing.
You are graded two ways, in order:
First, your tests must pass against the correct implementation. A test that fails on working code does not count.
Then, your tests run against six broken versions, each with one realistic bug that breaks one clause above. A broken version is caught when at least one of your tests fails on it. You never see the broken code, only which ones your tests let through.
A happy-path test catches the crude bugs. Catching all six means testing each clause on its own: uneven lengths, the tail, empty input, repeated whitespace.