Sha256: 9ae25a55c68cceec3ee23cbd387e418d8bee4c931b75236fd289babadc3fb79f

Contents?: true

Size: 994 Bytes

Versions: 124

Compression:

Stored size: 994 Bytes

Contents

# frozen_string_literal: true

RSpec.describe :in_groups do
  link :in_groups, from: :ree_array

  it "returns array size" do
    array = (1..7).to_a
    
    1.upto(array.size + 1) do |number|
      expect(number).to eq(in_groups(array, number).size)
    end
  end

  it "empty array" do
    expect([[], [], []]).to eq(in_groups([], 3))
  end

  it "with block" do
    array = (1..9).to_a
    groups = []

    in_groups(array, 3) do |group|
      groups << group
    end

    expect(in_groups(array, 3)).to eq(groups)
  end

  it "with perfect fit" do
    expect([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).to eq(in_groups((1..9).to_a, 3))
  end

  it "with padding" do
    array = (1..7).to_a

    expect([[1, 2, 3], [4, 5, nil], [6, 7, nil]]).to eq(in_groups(array, 3, fill_with: nil))
    expect([[1, 2, 3], [4, 5, "foo"], [6, 7, "foo"]]).to eq(in_groups(array, 3, fill_with: "foo"))
  end

  it "without padding" do
    expect([[1, 2, 3], [4, 5], [6, 7]]).to eq(in_groups((1..7).to_a, 3))
  end
end

Version data entries

124 entries across 124 versions & 1 rubygems

Version Path
ree_lib-1.0.44 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.43 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.42 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.41 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.40 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.39 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.38 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.37 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.36 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.35 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.34 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.33 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.32 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.31 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.30 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.29 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.28 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.27 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.26 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.24 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb