Update mcollective.init according to OSCI-855
[packages/precise/mcollective.git] / spec / unit / array_spec.rb
1 #!/usr/bin/env rspec
2
3 require 'spec_helper'
4
5 class Array
6   describe "#in_groups_of" do
7     it "should correctly group array members" do
8       [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]]
9     end
10
11     it "should padd missing data with correctly" do
12       arr = [1,2,3,4,5,6,7,8,9,10]
13
14       arr.in_groups_of(3).should == [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, nil, nil]]
15       arr.in_groups_of(3, 0).should == [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 0, 0]]
16       arr.in_groups_of(11).should == [[1,2,3,4,5, 6,7,8,9,10, nil]]
17       arr.in_groups_of(11, 0).should == [[1,2,3,4,5, 6,7,8,9,10, 0]]
18     end
19
20     it "should indicate when the last abtched was reached" do
21       arr = [1,2,3,4,5,6,7,8,9,10]
22
23       ctr = 0
24
25       [1,2,3,4,5,6,7,8,9,10].in_groups_of(3) {|a, last_batch| ctr += 1 unless last_batch}
26
27       ctr.should == 3
28     end
29   end
30 end