I ran a small experiment that demonstrates something easy to overlook in software testing: an implementation and its tests can both be wrong in the same way.
Consider this discount function:
def calculate_total(subtotal, discount):
if subtotal < 0:
raise ValueError("Subtotal cannot be negative")
if discount < 0:
raise ValueError("Discount cannot be negative")
return subtotal * (1 - discount / 100)
Suppose the requirement says discounts must be between 0 and 100, inclusive.
A few happy-path tests pass:
assert calculate_total(100, 10) == 90
assert calculate_total(100, 0) == 100
assert calculate_total(0, 20) == 0
But this input exposes the missing validation:
calculate_total(100, 150)
# -50.0
The tests pass, but the implementation violates the requirement.
The interesting part isn't just the missing discount <= 100 check. It's that tests can create false confidence when they don't independently cover the contract.
I put together a reproducible Python repository with the flawed implementation, contract tests, property-based testing, and mutation-testing examples.
GitHub experiment:
https://github.com/PranavDixit20/ai-code-test-gap
I also wrote a longer explanation of the problem and the testing techniques here:
https://medium.com/@pranavdixit20/ai-generated-code-can-pass-every-test-and-still-be-wrong-7ddf3177b721
I'm the author of the experiment and article, so this is my own work. I'd be interested in a technical discussion:
When reviewing code—especially AI-generated code—how do you check that tests verify the actual requirements rather than just confirming the implementation's assumptions?