Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Round-Robin Distribution Logic in Money Allocation #1073

Closed
wants to merge 1 commit into from

Conversation

tirosh
Copy link
Member

@tirosh tirosh commented Feb 21, 2024

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 the amount_to_distribute to be applied exclusively to the first element of the result 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 the amount_to_distribute is correctly applied to each element in the result 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.

@semmons99
Copy link
Member

two requests. please add a test since one was missing that would have caught this. also, please add your name to the contributors—if you like.

also, please check the failing tests.

@tirosh
Copy link
Member Author

tirosh commented Mar 5, 2024

Thank you for your feedback, @semmons99! As mentioned above, I did not succeed in writing a corresponding test in which the remaining_amount is above 1.

Upon further reflection, I think the reason for introducing the round-robin distribution was lack of precision. By increasing the precision to BigDecimal, the case described in #1033 seems to be solved and the round-robin distribution becomes obsolete.

That's why I have created another pull request #1082

Note: The only failing test has nothing to do with my changes, but apparently with the formatting for CHF

@tirosh
Copy link
Member Author

tirosh commented Mar 6, 2024

Resolved with this PR: #1082

@tirosh tirosh closed this Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants