Sha256: 70bcb1415f7418751587b9edb963a2c670ce6df87571314e21d2d5cd8f5e8b4c

Contents?: true

Size: 982 Bytes

Versions: 135

Compression:

Stored size: 982 Bytes

Contents

require 'bsearch'

describe "Bsearch" do

  it "should find first occurance" do
    index = %w(a b c c c d e f).bsearch_first {|x| x <=> "c"}
    index.should == 2

    index = %w(a b c e f).bsearch_first {|x| x <=> "c"}
    index.should == 2

  end

  it "should not find matches" do
    index = %w(a b e f).bsearch_first {|x| x <=> "c"}
    index.should == nil

    index = %w(a b e f).bsearch_last {|x| x <=> "c"}
    index.should == nil

  end

  it "should find upper and lower boundaries" do
    index = %w(a b e f).bsearch_lower_boundary {|x| x <=> "c"}
    index.should == 2

    index = %w(a b e f).bsearch_upper_boundary {|x| x <=> "c"}
    index.should == 2
  end

  it "should find ranges" do
    range = %w(a b c c c d e f).bsearch_range {|x| x <=> "c"}
    range.should == (2...5)

    range = %w(a b c d e f).bsearch_range {|x| x <=> "c"}
    range.should == (2...3)

    range = %w(a b d e f).bsearch_range {|x| x <=> "c"}
    range.should == (2...2)
    
  end

end

Version data entries

135 entries across 135 versions & 2 rubygems

Version Path
rhodes-7.6.0 spec/phone_spec/app/spec/bsearch_spec.rb
rhodes-7.5.1 spec/phone_spec/app/spec/bsearch_spec.rb
rhodes-7.4.1 spec/phone_spec/app/spec/bsearch_spec.rb
rhodes-7.1.17 spec/phone_spec/app/spec/bsearch_spec.rb
rhodes-6.2.0 spec/phone_spec/app/spec/bsearch_spec.rb
rhodes-6.0.11 spec/phone_spec/app/spec/bsearch_spec.rb
rhodes-5.5.18 spec/phone_spec/app/spec/bsearch_spec.rb
rhodes-5.5.17 spec/phone_spec/app/spec/bsearch_spec.rb
rhodes-5.5.15 spec/phone_spec/app/spec/bsearch_spec.rb
rhodes-5.5.0.22 spec/phone_spec/app/spec/bsearch_spec.rb
rhodes-5.5.2 spec/phone_spec/app/spec/bsearch_spec.rb
rhodes-5.5.0.7 spec/phone_spec/app/spec/bsearch_spec.rb
rhodes-5.5.0.3 spec/phone_spec/app/spec/bsearch_spec.rb
rhodes-5.5.0 spec/phone_spec/app/spec/bsearch_spec.rb
tauplatform-1.0.3 spec/phone_spec/app/spec/bsearch_spec.rb
tauplatform-1.0.2 spec/phone_spec/app/spec/bsearch_spec.rb
tauplatform-1.0.1 spec/phone_spec/app/spec/bsearch_spec.rb
rhodes-3.5.1.12 spec/phone_spec/app/spec/bsearch_spec.rb
rhodes-3.3.5 spec/phone_spec/app/spec/bsearch_spec.rb
rhodes-3.4.2 spec/phone_spec/app/spec/bsearch_spec.rb