The decimal that changed its meaning
A checkout field keeps its name and decimal type but begins including tax.
The interview prompt
A checkout field keeps its name and decimal type but begins including tax. Your schema check passes. Write a contract and a test that catches it, including one example where your proposed test would fail to detect the change.
An independent observation makes the test informative
Use integer cents for the fixture. A book is listed at 2,000 cents pre-tax, a promotion reduces it by 200, and tax is 180. The payment receipt records 1,980 cents charged. Define whether tax was computed after the discount for this fixture. The invariant is gross item price minus discount plus tax equals charged amount. State how shipping, tips, and multi-line rounding are handled or explicitly exclude them from the fixture.
Separately assert that the field named pre-tax net equals 1,800, because the receipt check alone might still pass if several fields drift together. Include a zero-tax purchase as a boundary case and a nonzero-tax purchase as a discriminating case. Check against an independent receipt or independently computed fixture. Running two aliases of the same checkout expression only demonstrates self-consistency.
A usable contract also specifies one row per capture line, stable keys, the currency, effective timestamp, correction policy, ownership, expected population, and freshness. Put the examples beside that agreement so a producer can run them before rollout. Contract validation after deployment remains necessary for defects a test fixture did not anticipate.
The model behind the answer
The bookstore exports a field called amount. Last week it contained the pre-tax price. This week the checkout team sends the tax-inclusive amount in the same decimal field. The schema validator accepts every row. A $20 book with $2 of tax now appears to sell for $22 before tax.
A useful data contract names the producer, the consumer-visible grain, identifiers, units, clock, meaning, and service commitments. In this case, define separate pre-tax, tax, and charged amounts and their currency. State how discounts and refunds enter the equation. Use at least one fixture with nonzero tax. A fixture containing only tax-exempt purchases would allow the change to pass unnoticed.
For an interview, write one proposed assertion in full. For an undiscounted sale with no other charges, the pre-tax amount plus tax must equal the charged amount at the agreed rounding precision. That turns a sentence about meaning into a check both teams can run. Open Data Contract Standard
Break the test that the coding agent wrote
The agent generated the SQL and its expected output from the same checkout expression. As reviewer, cover the implementation and calculate an independent receipt: 2,000 cents less 200 discount plus 180 tax equals 1,980 charged. The pre-tax net is 1,800.
Reviewer decision. Temporarily substitute charged amount for pre-tax net. The nonzero-tax example must fail even though the type check stays green. Keep a zero-tax example as a control. If both pass the substitution, repair the test before accepting another implementation.
Further reading. Data Contracts, 1st ed., on semantic constraints on data values beyond their types.
One more question
The producer switches from dollars to cents and multiplies every monetary field by 100. Will the arithmetic identity catch it?
Check your reasoning
No. It preserves the equation. A fixture anchored in known external amounts, explicit units, and reconciliation to independently recorded captures can reveal the scale change. Review distributions by currency as an additional signal.
Previous · When one school district becomes half the traffic · Next · Migrate the consumers that depend on the field · Complete series map