Welcome to the team that mints order identifiers. A sequence number becomes ORD-<8-digit zero-padded-<check digit, where the check digit is the sum of the eight body digits modulo 10. format_code mints the code for a seq…
Welcome to the team that mints order identifiers. A sequence number becomes ORD-<8-digit zero-padded>-<check digit>, where the check digit is the sum of the eight body digits modulo 10. format_code mints the code for a sequence number and is_valid says whether a code can be trusted.
There is one ticket below. Fix as much of it as you can in 35 minutes. It is graded by several separate checks, so fixing one part (the padding or the validation) still counts even if the other is not done.
is_valid accepts a well-formed code with a correct check digit and rejects anything else.Order codes are malformed and validation does not really validate. format_code does not zero-pad the body, which also means the check digit is computed over the wrong string. And is_valid only checks the prefix, so a wrong check digit or a missing segment passes.
format_code(42) is "ORD-00000042-6" and format_code(0) is "ORD-00000000-0".is_valid accepts a correct code and rejects one with a wrong check digit.is_valid rejects a malformed code missing its check segment.Keep the public functions format_code and is_valid; do not add new entry points.
checksum.py (check_digit: the sum of the body digits modulo 10) and codes.py (format_code and is_valid). The shipped regression tests are in tests/visible/; every one of them fails until the bugs are fixed.pytest tests/visible.Adapted from treasure567/bloomberg-practice (round-1/zephyr @ 8de07d5), used with the author's permission.
Visible test command
pytest tests/visibleThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
order-identifier-padding-and-validation
Changes under src/ are evaluated.