Sha256: 94f69df2bf98e75048a2378dfd426c8cdeb0a4910388d8e21f94e75aa9a5b222

Contents?: true

Size: 954 Bytes

Versions: 23

Compression:

Stored size: 954 Bytes

Contents

describe "Array#at" do
  it "returns the (n+1)'th element for the passed index n" do
    a = [1, 2, 3, 4, 5, 6]
    a.at(0).should == 1
    a.at(1).should == 2
    a.at(5).should == 6
  end

  it "returns nil if the given index is greater than or equal to the array's length" do
    a = [1, 2, 3, 4, 5, 6]
    a.at(6).should == nil
    a.at(7).should == nil
  end

  it "returns the (-n)'th element from the last, for the given negative index n" do
    a = [1, 2, 3, 4, 5, 6]
    a.at(-1).should == 6
    a.at(-2).should == 5
    a.at(-6).should == 1
  end

  it "returns nil if the given index is less than -len, where len is length of the array" do
    a = [1, 2, 3, 4, 5, 6]
    a.at(-7).should == nil
    a.at(-8).should == nil
  end

  it "does not extend the array unless the given index is out of range" do
    a = [1, 2, 3, 4, 5, 6]
    a.length.should == 6
    a.at(100)
    a.length.should == 6
    a.at(-100)
    a.length.should == 6
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

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