Money::Allocation does not allocate all pennies
Mongey opened this issue · 0 comments
Mongey commented
The documentation states that is should allocate all pennies
Splits a given amount in parts without losing pennies. The left-over pennies will be distributed round-robin amongst the parts.
But it does not.
Here's a test
describe "an allocation seen in the wild" do
it "allocates the full amount" do
amount = 700273
allocations = [1.1818583143661, 1.1818583143661, 1.1818583143661, 1.1818583143661, 1.1818583143661, 1.1818583143661, 1.1818583143661, 1.170126087450276, 1.0, 1.0, 1.0, 1.0]
result = described_class.generate(amount, allocations)
expect(result).to eq([61566, 61565, 61565, 61565, 61565, 61565, 61565, 60953, 52091, 52091, 52091, 52091])
expect(result.reduce(&:+)).to eq(amount)
end
end
Here, we start with 700273, and end with 700272, losing a penny.