A discount came back as 110% in a test last week and I spent a solid ten minutes insisting that was impossible. I had a setter. The setter clamped. Math.Clamp(value, 0, 100) , sitting right there, no way past it. Except there was a way past it, and I'd built the door myself.
Here's the property, more or less how it looked:
sealed class DiscountOld { private int _percent ;
public int Percent { get => _percent ; set => _percent = Math . Clamp ( value , 0 , 100 ); } }
Enter fullscreen mode
Exit fullscreen mode
Nothing wrong with that. Assign Percent = 150 and you get 100 back. I'd tested exactly that case and moved on. The setter does its job every single time it runs. That last bit is the part I didn't think hard enough about.
The line I wrote three weeks later
A seasonal promo needed a flat bump, and I added a method to the same class to do it.β¦