Fix the reference discount that tests check against

Review the AI's codeMedium15 minAnthropic style

Your task

You asked an agent to test a discount function. It ran the code, copied what it printed into the asserts, and the tests passed with a rounding bug inside. Now the team wants the discounted price computed straight from the spec, so tests can assert against it.

An assistant wrote discount_amount(price, pct_bps). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • price: the price in whole currency units, an integer. The tests use values up to 1,000,000, and some negative ones.
  • pct_bps: the discount in basis points, an integer. A basis point is a hundredth of a percent, so 1000 means 10% off.
  • Return the discounted price as an integer, or -1 for invalid input.

Rules the tests check:

  • A negative price returns -1.
  • A pct_bps below 0 or above 10000 returns -1. Both 0 and 10000 are valid.
  • Otherwise the exact discounted price is price * (10000 - pct_bps) / 10000.
  • Round it half up to a whole number. A value exactly halfway between two whole numbers goes up. Any other value goes to the nearest whole number.
  • The result must be exact for every valid input, including every value that is exactly halfway.

Examples

discount_amount(price: int, pct_bps: int) -> int
Example 1
Inputdiscount_amount(100, 1000)
Output90
Example 2
Inputdiscount_amount(95, 1000)
Output86
Example 3
Inputdiscount_amount(99, 1000)
Output89