fl00r/pickup

devision by 0 sometimes

Opened this issue · 3 comments

Sometimes when weight includes 0 division by zero occures

Loading development environment (Rails 4.2.0)
[1] pry(main)> pond = {a: 1, b: 4, t:0}
=> {:a=>1, :b=>4, :t=>0}
[2] pry(main)> pu = Pickup.new(pond, uniq: true)
=> #<Pickup:0x00000005e6a6e0 @key_func=nil, @list={:a=>1, :b=>4, :t=>0}, @uniq=true, @weight_func=nil>
[3] pry(main)> pu.pick(3)
=> [:b, :t, :a]
[4] pry(main)> pu.pick(3)
=> [:b, :t, :a]
[5] pry(main)> pu.pick(3)
=> [:b, :t, :a]
[6] pry(main)> pu.pick(3)
ZeroDivisionError: divided by 0
from /home/ilya/.rvm/gems/ruby-2.2.0@blc/gems/pickup-0.0.10/lib/pickup.rb:128:in `block in get_random_items'
fl00r commented

Hi! Thank you for your feedback.
Weight of zero is causing this edge case.
I will fix it soon

fl00r commented

Fixed

It seems still have this problem when I try the example above.