forked from choria-legacy/marionette-collective
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.rb
30 lines (22 loc) · 876 Bytes
/
array.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env ruby
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