Sha256: 8edaa6a0cbe733dcd563c5e112f026e6eefdda0a1d09fe6b0817887159cc620c

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

require File.expand_path('../../spec_helper', File.dirname(__FILE__))

require 'hamster/list'

describe Hamster::List do

  [:combinations, :combination].each do |method|

    describe "##{method}" do

      it "is lazy" do
        lambda { Hamster.stream { fail }.combinations(2) }.should_not raise_error
      end

      [
        [["A", "B", "C", "D"], 1, [["A"], ["B"], ["C"], ["D"]]],
        [["A", "B", "C", "D"], 2, [["A", "B"], ["A", "C"], ["A", "D"], ["B", "C"], ["B", "D"], ["C", "D"]]],
        [["A", "B", "C", "D"], 3, [["A", "B", "C"], ["A", "B", "D"], ["A", "C", "D"], ["B", "C", "D"]]],
        [["A", "B", "C", "D"], 4, [["A", "B", "C", "D"]]],
        [["A", "B", "C", "D"], 0, [[]]],
        [["A", "B", "C", "D"], 5, []],
        [[], 0, [[]]],
        [[], 1, []],
      ].each do |values, number, expected|

        expected = expected.map { |x| Hamster.list(*x) }

        describe "on #{values.inspect} in groups of #{number}" do

          before do
            @original = Hamster.list(*values)
            @result = @original.send(method, number)
          end

          it "preserves the original" do
            @original.should == Hamster.list(*values)
          end

          it "returns #{expected.inspect}" do
            @result.should == Hamster.list(*expected)
          end

        end

      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hamster-0.2.7 spec/hamster/list/combinations_spec.rb
hamster-0.2.6 spec/hamster/list/combinations_spec.rb