Module: Array::Cross::Etest

Defined in:
lib/vex/base/array/cross.rb,
lib/vex/base/array/each_batch.rb

Instance Method Summary collapse

Instance Method Details

#test_crossObject


20
21
22
23
24
25
# File 'lib/vex/base/array/cross.rb', line 20

def test_cross
  assert_equal( [[1,1]],                            [1].cross([1])  )
  assert_equal( [[1,1], [2,1]],                     [1, 2].cross([1])  )
  assert_equal( [[1,1], [1,3], [2,1], [2,3]],       [1, 2].cross([1, 3])  )
  assert_equal( [],                                 [1, 2].cross([])  )
end

#test_each_batchObject


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vex/base/array/each_batch.rb', line 17

def test_each_batch
  r = []
  [1,2,3,4,5,6,7,8,9].each_batch 3 do |batch|
    r << batch
  end 
  
  assert_equal( [[1,2,3],[4,5,6],[7,8,9]], r)

  r = []
  [1,2,3,4,5,6,7].each_batch 3 do |batch|
    r << batch
  end 
  
  assert_equal( [[1,2,3],[4,5,6],[7]], r)
end