Skip to content

< all problems43 · Level 07, Evals

Write the Tests That Catch the Bug

medium · write tests · Evals

chunk_document(text, chunk_size, overlap) is already implemented and correct. Write the tests that would catch a bug in it.

Its contract:

  1. Each chunk holds at most chunk_size words.
  2. Each chunk after the first starts overlap words before the previous one ended.
  3. Chunks are strings, words rejoined with single spaces.
  4. Never an empty chunk, and never a chunk whose words are all already covered by the previous one.
  5. 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.