Sha256: 4c272966b57bb321aee15dbf2bd5aecaf9bfecb131a71f1e9bd32d78761bac01

Contents?: true

Size: 1.05 KB

Versions: 21

Compression:

Stored size: 1.05 KB

Contents

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

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

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

  it "returns the take count elements if given a count" do
    @enum.take(2).should == [4, 3]
    @enum.take(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.take(0).should == []
    empty.take(1).should == []
    empty.take(2).should == []
  end

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

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

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

Version data entries

21 entries across 21 versions & 1 rubygems

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