Sha256: d88f28fefb914e8baa6bb1aca58256f56173eeb90a84b1b7b444c04ace355999

Contents?: true

Size: 877 Bytes

Versions: 45

Compression:

Stored size: 877 Bytes

Contents

#!/usr/bin/env rspec

require 'spec_helper'

class Array
  describe "#in_groups_of" do
    it "should correctly group array members" do
      [1,2,3,4,5,6,7,8,9,10].in_groups_of(5).should == [[1,2,3,4,5], [6,7,8,9,10]]
    end

    it "should padd missing data with correctly" do
      arr = [1,2,3,4,5,6,7,8,9,10]

      arr.in_groups_of(3).should == [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, nil, nil]]
      arr.in_groups_of(3, 0).should == [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 0, 0]]
      arr.in_groups_of(11).should == [[1,2,3,4,5, 6,7,8,9,10, nil]]
      arr.in_groups_of(11, 0).should == [[1,2,3,4,5, 6,7,8,9,10, 0]]
    end

    it "should indicate when the last abtched was reached" do
      arr = [1,2,3,4,5,6,7,8,9,10]

      ctr = 0

      [1,2,3,4,5,6,7,8,9,10].in_groups_of(3) {|a, last_batch| ctr += 1 unless last_batch}

      ctr.should == 3
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
mcollective-client-2.12.5 spec/unit/mcollective/array_spec.rb
mcollective-client-2.12.4 spec/unit/mcollective/array_spec.rb
mcollective-client-2.12.3 spec/unit/mcollective/array_spec.rb
mcollective-client-2.12.1 spec/unit/mcollective/array_spec.rb
mcollective-client-2.12.0 spec/unit/mcollective/array_spec.rb
mcollective-client-2.10.6 spec/unit/mcollective/array_spec.rb
mcollective-client-2.11.4 spec/unit/mcollective/array_spec.rb
mcollective-client-2.11.3 spec/unit/mcollective/array_spec.rb
mcollective-client-2.11.2 spec/unit/mcollective/array_spec.rb
mcollective-client-2.11.1 spec/unit/mcollective/array_spec.rb
mcollective-client-2.11.0 spec/unit/mcollective/array_spec.rb
mcollective-client-2.10.4 spec/unit/mcollective/array_spec.rb
mcollective-client-2.10.3 spec/unit/mcollective/array_spec.rb
mcollective-client-2.10.2 spec/unit/mcollective/array_spec.rb
mcollective-client-2.10.1 spec/unit/mcollective/array_spec.rb
mcollective-client-2.10.0 spec/unit/mcollective/array_spec.rb
mcollective-client-2.8.7 spec/unit/mcollective/array_spec.rb
mcollective-client-2.8.5 spec/unit/mcollective/array_spec.rb
mcollective-client-2.8.8 spec/unit/mcollective/array_spec.rb
mcollective-client-2.8.6 spec/unit/mcollective/array_spec.rb