
Two devices log a counter in the same two-byte field. A firmware update changed the documentation around byte order. Inspecting the hex bytes and interpreting both conventions makes the disagreement reproducible. The all-ones test alone cannot reveal a swapped byte order. An asymmetric fixture is what makes this regression visible.
Set up the smallest useful example
The script runs int.from_bytes against three independent inputs. Each call starts from the value shown, so changing one example leaves the other expectations available for comparison. The table records real return values from the example. Quotation marks around text in the table make its boundaries visible.
def evaluate(value):
return (int.from_bytes(bytes.fromhex(value),'big'),int.from_bytes(bytes.fromhex(value),'little'))
for sample in ['0001', '0100', 'ffff']:
print(evaluate(sample))What the three inputs produce
| Input to evaluate | Observed result |
|---|---|
| '0001' | [1, 256] |
| '0100' | [256, 1] |
| 'ffff' | [65535, 65535] |
For '0001', the observed output is [1, 256]. With '0100', it becomes [256, 1]. A UI screenshot alone would discard some of this evidence. Keep the original data, the expected return value and the runtime version together when filing a regression report.
For 'ffff', the operation returns 2 top-level items. An assertion on that count would miss a change in their contents. Capture the expected sequence or compare membership explicitly if order has no meaning in the product.
Choosing the behaviour to ship
Confirm signedness independently. A high bit can mean a large positive counter or a negative signed value, depending on the wire contract.
A practical test can begin with assert evaluate('0001') == (1, 256). Add the other rows as separate expectations so one failure identifies the input that changed. For a service fed by stored data, repeat the check on one anonymized record from an earlier version of its file or message format.
The boundary case most likely to be missed
Pair a symmetric header with a deliberately asymmetric counter in a binary fixture. If the encoded bytes are printed in the device manual, save those literal bytes in the test rather than generating them with the same encoder that the test is meant to check.
The same Python function was also run with '' / '0001 ' / '1000'. These additional inputs change the boundary without changing the implementation. An exception name in the table records where the operation rejects an input; a returned empty or zero value records a successful call. Choose deliberately which of those outcomes the surrounding feature should expose.
| Additional fixture | Result or exception |
|---|---|
| '' | [0, 0] |
| '0001 ' | [1, 256] |
| '1000' | [4096, 16] |
Tuples are printed with list-style brackets in the comparison table. The runnable Python assertion preserves the actual tuple return type.
Python’s functions reference · Python standard library
Sources and further reading
Cover photograph: Cherry MX Switches and Razer Switch by Ox1997cow. CC BY-SA 3.0. Cropped and typeset for this cover. The photograph illustrates the topic. This image adaptation uses the same share-alike license.
