Fix Round-Robin Distribution Logic in Money Allocation #1073
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.
This pull request addresses a flaw in the round-robin distribution logic within the money allocation functionality. Previously, the
index
variable was reset to 0 at the beginning of each iteration of the while loop, causing all operations for distributing theamount_to_distribute
to be applied exclusively to the first element of theresult
array (result[0]
). This prevented the correct round-robin distribution across all elements of the array.The fix involves initializing the
index
variable outside the while loop, allowing it to retain its value across iterations. This change ensures that theamount_to_distribute
is correctly applied to each element in theresult
array in a round-robin fashion.The fact was probably not noticed, as the
remaining_amount
never seems to be above 1 due to the previous distribution (at least I have not succeeded in constructing a corresponding test case). In this respect, no erroneous results were produced. Nevertheless, I am of the opinion that it should be corrected.