KatInterview

Test Plan for Straight-Line vs Path Word Search

Arrays & HashingModel answer
MediumModel answerArrays & Hashingtestingtddgrids

Last updated

Build a TDD plan, concrete cases, property invariants and stress tests for two grid word-search functions that must disagree on key inputs.

You are handed two grid-search functions and asked to own their quality end to end:

  • in_line(grid, word) -> bool — true when word occupies consecutive cells along one fixed straight direction, chosen from the eight compass directions, without turning.
  • on_path(grid, word) -> bool — true when word can be spelled by a walk of four-directionally adjacent cells where no cell is visited twice; turns are allowed.

Shared conventions: an empty word is always True (even on an empty grid), an empty grid with a non-empty word is False, comparison is case-sensitive with no normalization unless the spec says otherwise, and malformed input (ragged rows, cells that are not single characters, a non-string word) raises an error.

Produce a test plan and a test-driven development workflow: enumerate concrete cases with expected outcomes for both functions, say which cases are the most discriminating and why, explain how you would layer unit tests, property-based tests and stress tests, define pass/fail criteria, and note how test pressure shapes the implementation (recursion depth, pruning, complexity). There is no automatic judge — argue your plan in prose and back it with a reference implementation sketch.

Hints

Hint 1

Start by writing down the contract for each function and one failing test per contract clause — the vocabulary of the two functions is where most bugs hide.

Hint 2

Hunt for inputs where the two functions must give different answers; those expose far more than cases where both agree.

Hint 3

Your grid test doubles as an oracle: a hand-rolled brute-force enumerator is fast enough at 4x4 and lets you check thousands of random inputs.