File tree 2 files changed +10
-0
lines changed
2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,12 @@ require "../spec_helper"
2
2
3
3
describe Money ::Allocate do
4
4
describe " #allocate" do
5
+ context " with all zeros" do
6
+ it " allocates evenly" do
7
+ Money .us_dollar(100 ).allocate([0 , 0 ]).map(& .cents).should eq [50 , 50 ]
8
+ end
9
+ end
10
+
5
11
it " takes no action when one gets all" do
6
12
Money .us_dollar(5 ).allocate({1.0 }).map(& .cents).should eq [5 ]
7
13
end
Original file line number Diff line number Diff line change @@ -38,6 +38,10 @@ struct Money
38
38
allocations = allocations_from_splits(splits)
39
39
raise ArgumentError .new(" Splits add to more then 100%" ) if allocations > 1.0
40
40
41
+ if splits.all?(& .zero?)
42
+ allocations = splits.size.to_f
43
+ end
44
+
41
45
amounts, left_over = amounts_from_splits(allocations, splits)
42
46
delta = left_over > 0 ? 1 : -1
43
47
size = amounts.size
You can’t perform that action at this time.
0 commit comments