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.124 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.123 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.122 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.121 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.120 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.119 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.118 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.117 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.116 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.115 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.114 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.113 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.112 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.111 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.110 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.109 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.108 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.107 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.106 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb
ree_lib-1.0.105 lib/ree_lib/packages/ree_array/spec/ree_array/functions/in_groups_spec.rb