Sha256: 2de6708b8f43b6ec202bcb58b95f88fa5bf47375da5f3c8bed7fea8d0c1575d9

Contents?: true

Size: 1.07 KB

Versions: 21

Compression:

Stored size: 1.07 KB

Contents

describe "Enumerable#first" do
  before :each do
    @values = [4,3,2,1,0,-1]
    @enum = EnumerableSpecs::Numerous.new(*@values)
  end

  it "returns the first element" do
    EnumerableSpecs::Numerous.new.first.should == 2
    EnumerableSpecs::Empty.new.first.should == nil
  end

  it "returns nil if self is empty" do
    EnumerableSpecs::Empty.new.first.should == nil
  end

  it "returns the first count elements if given a count" do
    @enum.first(2).should == [4, 3]
    @enum.first(4).should == [4, 3, 2, 1]
  end

  it "returns an empty array when passed a count on an empty array" do
    empty = EnumerableSpecs::Empty.new
    empty.first(0).should == []
    empty.first(1).should == []
    empty.first(2).should == []
  end

  it "returns an empty array when passed count == 0" do
    @enum.first(0).should == []
  end

  it "returns an array containing the first element when passed count == 1" do
    @enum.first(1).should == [4]
  end

  it "returns the entire array when count > length" do
    @enum.first(100).should == @values
    @enum.first(8).should == @values
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
opal-0.3.41 spec/core/enumerable/first_spec.rb
opal-0.3.40 spec/core/enumerable/first_spec.rb
opal-0.3.39 spec/core/enumerable/first_spec.rb
opal-0.3.38 spec/core/enumerable/first_spec.rb
opal-0.3.37 spec/core/enumerable/first_spec.rb
opal-0.3.36 spec/core/enumerable/first_spec.rb
opal-0.3.35 spec/core/enumerable/first_spec.rb
opal-0.3.34 spec/core/enumerable/first_spec.rb
opal-0.3.33 spec/core/enumerable/first_spec.rb
opal-0.3.32 spec/core/enumerable/first_spec.rb
opal-0.3.31 spec/core/enumerable/first_spec.rb
opal-0.3.30 spec/core/enumerable/first_spec.rb
opal-0.3.29 spec/core/enumerable/first_spec.rb
opal-0.3.28 spec/core/enumerable/first_spec.rb
opal-0.3.27 spec/core/enumerable/first_spec.rb
opal-0.3.26 spec/core/enumerable/first_spec.rb
opal-0.3.25 spec/core/enumerable/first_spec.rb
opal-0.3.22 spec/core/enumerable/first_spec.rb
opal-0.3.21 test/core/enumerable/first_spec.rb
opal-0.3.20 test/core/enumerable/first_spec.rb