0
0
Fork 0

Fix division by zero

If the maximum value is zero, the maximum value will be set to one.
This avoids a division by zero.
This commit is contained in:
Stormwind 2015-10-21 09:00:33 +02:00
parent 47aa9c301a
commit 12d5858ff8
2 changed files with 20 additions and 0 deletions

View File

@ -40,6 +40,8 @@ module Rubella
# Get the maximum of commits
max = input.sort.pop
# Sets maximum to 1 if its 0 to avoid division by zero
max = 1 if max == 0
i = 0
input.each do |commits|

View File

@ -40,4 +40,22 @@ describe Rubella::Weighting::PerCount, '.parse' do
)
end
it "writes 0 if value is 0" do
input = [0, 2, 1, 3, 1, 4, 5, 2, 1, 2, 3, 4, 2, 1]
weighting = Rubella::Weighting::PerCount.new 7
storage = weighting.parse(input)
expect(storage.data[0][0]).to eq(0.0)
end
it "sets 0 to 0 even if the maximum value is 0" do
input = [0, 0, 0, 0]
weighting = Rubella::Weighting::PerCount.new 2
storage = weighting.parse(input)
expect(storage.data[0][0]).to eq(0.0)
end
end