Fix for Equality check on floating point values#295
Merged
samsmithnz merged 5 commits intomainfrom Dec 4, 2025
Merged
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Collaborator
Author
|
@copilot, make sure you fix this rule on all methods in this file. |
Contributor
|
@samsmithnz I've opened a new pull request, #298, to work on those changes. Once the pull request is ready, I'll request review from you. |
Pull Request Test Coverage Report for Build 19940168901Details
💛 - Coveralls |
Co-authored-by: samsmithnz <8389039+samsmithnz@users.noreply.github.com>
[WIP] Fix equality check on floating point values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To fix the issue, the code should avoid comparing floating-point values for equality using
==. SinceSystem.Math.Round(result, 0)is meant to convert the floating-pointresultto the nearest whole number, it is better to either:Since the test is logically intended to check that, after rounding, the number of M&Ms matches the expected integer, the most robust approach is to cast the rounded result to an integer and then compare it to the integer value 45. To make the code clearer, both values being compared should be integers.
Specifically, on line 71, replace:
with:
This both simplifies the test assertion (using
AreEqualrather thanIsTrue), and compares integer values, removing reliance on floating-point equality.Suggested fixes powered by Copilot Autofix. Review carefully before merging.