Pin Legacy Shipping Rules With Golden Master Characterization Tests

Last updated: November 29, 2026

Quick Overview

You inherit an untested shipping cost function full of branches that a client wants to change. Before editing it, write characterization tests that capture its current behaviour across a meaningful input grid, and show how they catch an accidental change.

Thoughtworks
Software Engineering Fundamentals
Software Engineer
Thoughtworks
November 29, 2026
Software Engineer
Take-home Project
Software Engineering Fundamentals
Easy

0

0

0 solved


You inherit an untested shipping cost function full of branches that a client wants to change. Before editing it, write characterization tests that capture its current behaviour across a meaningful input grid, and show how they catch an accidental change.

Working effectively with legacy code is daily work on Thoughtworks modernisation projects, and a take-home or pairing round can hand you code with no tests. The interviewer checks that you protect behaviour before changing it, choose inputs at boundaries, and keep the existing quirks until someone decides they are bugs.

What the Interviewer Expects
  • Records current outputs instead of what the code should do
  • Chooses inputs at boundaries (weight 0, just below and at 20 kg, unknown zone)
  • Uses a combinatorial grid that covers flag interactions
  • Makes the golden file reviewable and deterministic
  • Notes suspicious behaviour as questions for the client rather than fixing silently
Key Topics to Cover
Characterization tests
Legacy code
Approval testing
Boundary values
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • When would you delete these tests?
  • How do you characterise code that calls a database or the current time?
  • Which behaviours here look like bugs, and how would you raise them?
  • How would mutation testing tell you whether the grid is good enough?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

Goal is a safety net, not correctness. Every combination of weight, zone, express and member flags I can reasonably enumerate should produce exactly today's output after a refactor....

High-Level Design

Read the code to find branch points: zone has three paths with an implicit default, express switches at 20 kg, member discounts skip intl. Pick weights around each boundary, include an unknown zone to...


Submit Your Answer
Markdown supported

Related Questions