KatInterview

Building a Reliable Test Suite When Samples Are Scarce

BehavioralModel answer
MediumModel answerBehavioraltestingedge-casesstress-testing

Last updated

Describe a repeatable method for writing your own tests on a timed coding assessment: edge-case categories, independent expected outputs, brute-force comparison, and a clear stopping rule.

You are taking a timed online coding assessment. The problem comes with only one or two sample tests, and the instructions tell you that you are expected to write additional tests yourself before submitting.

Explain how you would build a trustworthy test set under that time pressure. Your answer should cover:

  1. A repeatable checklist of edge-case categories you run through for any problem, and the kind of bug each category tends to expose.
  2. How you produce inputs and expected outputs quickly, without simply trusting what your own solution prints.
  3. How you use a reference implementation (an oracle) to cross-check your optimized solution.
  4. How you decide you have tested enough, for example whether a handful of well-chosen cases (say 5 to 10) is defensible, and what you do if time runs short.

Be concrete: name specific test inputs, and if you like, include a short code sketch of a comparison harness.

Hints

Hint 1

Start from the problem's constraints: every stated limit, and every point where the statement is ambiguous, suggests a test.

Hint 2

Separate two concerns: small random inputs are for checking correctness against a naive solution, while a single maximum-size input is for checking running time.

Hint 3

An expected output is only meaningful if it came from somewhere independent of the code under test, such as a hand derivation or a structurally different brute-force solution.

Hint 4

Define stopping criteria before you begin (categories covered, comparison run passes, worst-case timing is fine), so you do not keep testing indefinitely.