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 allocate panic #123

Merged
merged 6 commits into from
Nov 7, 2022
Merged

Fix allocate panic #123

merged 6 commits into from
Nov 7, 2022

Conversation

evilnoxx
Copy link
Contributor

  • Allow allocating zero amount with zero ratios
  • Allow allocating an amount with zero ratios (gives zero amount to all parties)
  • Added some extra test cases

@@ -282,6 +282,12 @@ func (m *Money) Allocate(rs ...int) ([]*Money, error) {
total += party.amount
}

// if the sum of all ratios is zero, then we just returns zeros and don't do anything
// with the leftover
if sum == 0 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it work with the case when ratios are equal to {-50, 50}? The sum is 0, how this works? To be honest with you, I'm not really sure what negative ratio means and I expect to always get unsigned integer, is there a use case I'm missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't come up with a use case for negative ratios. I've added a check, that returns a new error if any of the ratios are negative.

@Rhymond Rhymond merged commit aced7c7 into Rhymond:master Nov 7, 2022
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