Repository navigation
Specify precision / tolerance for interest checks in "Interest Is Interesting" - #2501
Conversation
|
This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested. If this PR does not affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), please add the following to the merge-commit message which will stops student's tests from re-running. Please copy-paste to avoid typos. For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping |
| public void Interest_on_negative_balance() | ||
| { | ||
| Assert.Equal(-321.3m, SavingsAccount.Interest(-10000.0m)); | ||
| Assert.Equal(-321.3m, SavingsAccount.Interest(-10000.0m), precision: 4); |
There was a problem hiding this comment.
Shouldn't the precision by 1 here as there is just a single decimal point being checked?
If so, the other tests also need to be updated.
There was a problem hiding this comment.
That was a copy and paste error from Interest_on_large_balance that I forgot to update. That should have been a precision of 1.
For Interest_on_negative_balance, a precision of 1 would compare -321.3 to -321.3.
Expected: -321.3
Actual: -321.3000059127807617187500000
For Interest_on_medium_balance, a precision of 3 would compare 81.050 vs 81.050.
Expected: 81.0498379
Actual: 81.04984047491550445556640625
For Interest_on_large_balance, a precision of 4 would compare 856.3698 vs 856.3698.
Expected: 856.3698
Actual: 856.3697670021057128906250000
So for that set, I think the precisions are reasonable.
Related to #2500 and https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/11/decimal-biginteger-floating-point-conversions. This should be merged so the other PR can then be rebased for CI purposes. It shouldn't hopefully break solutions on .NET 10 or .NET 11.