Sha256: 5bf97ee92625a8f15e90da34f05ceabe3432c64aa9d6e474897047d5c9beb668

Contents?: true

Size: 1011 Bytes

Versions: 28

Compression:

Stored size: 1011 Bytes

Contents

# encoding: utf-8

require 'liquid/weighted_selector'

describe WeightedSelector do

  describe "#empty?" do

    it do
      should be_empty
    end

    context do

      before do
        subject.add 'a', 0
      end

      it do
        should_not be_empty
      end

    end
  end

  describe '#pick_one' do

    context do

      its(:pick_one){ should == nil }

    end

    context do

      before do
        subject.add 'a', 2
        subject.add 'b', 2
        subject.add 'c', 0
      end

      it do
        ['a', 'b'].should include subject.pick_one
      end

    end

    context do

      before do
        subject.add 'a', 2
        subject.add 'b', 2
        subject.add 'c', 0
        subject.delete 'a'
      end

      its(:pick_one){ should == 'b' }
      its(:pick_one_with_index){ should == ['b', 0] }

    end

    context do

      before do
        Kernel.stub(:rand).and_return(1.00)
        subject.add 'a', 0.1
      end

      its(:pick_one){ should == 'a' }

    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
liquid-ext-3.5.3 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.5.2 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.5.0 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.4.2 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.4.1 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.4.0 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.3.10 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.3.9 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.3.8 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.3.7 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.3.6 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.3.5 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.3.4 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.3.3 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.3.2 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.3.0 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.2.0 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.1.2 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.1.1 spec/lib/liquid/weighted_selector_spec.rb
liquid-ext-3.1.0 spec/lib/liquid/weighted_selector_spec.rb