Sha256: 861135aee09876bc5c7080732981407465ad3cf4e583ac2534dd48b12b2f8f71

Contents?: true

Size: 1.16 KB

Versions: 17

Compression:

Stored size: 1.16 KB

Contents

describe "Enumerable#find_index" do
  before :each do
    @elements = [2, 4, 6, 8, 10]
    @numerous = EnumerableSpecs::Numerous.new(*@elements)
  end

  it "passes each entry in enum to block while block when block is false" do
    visited_elements = []
    @numerous.find_index do |element|
      visited_elements << element
      false
    end
    visited_elements.should == @elements
  end

  it "returns nil when the block is false" do
    @numerous.find_index {|e| false }.should == nil
  end

  it "returns the first index for which the block is not false" do
    @elements.each_with_index do |element, index|
      @numerous.find_index {|e| e > element - 1 }.should == index
    end
  end

  it "returns the first found index" do
    repeated = [10, 11, 11, 13, 11, 13, 10, 10, 13, 11]
    numerous_repeat = EnumerableSpecs::Numerous.new(*repeated)
    repeated.each do |element|
      numerous_repeat.find_index(element).should == element - 10
    end
  end

  it "returns nil when the element not found" do
    @numerous.find_index(-1).should == nil
  end

  it "ignores the block if an argument is given" do
    @numerous.find_index(-1) {|e| true }.should == nil
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

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