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:
parent
47aa9c301a
commit
12d5858ff8
|
@ -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|
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue