Skip to content

Instantly share code, notes, and snippets.

@alandotcom
Forked from dbc-challenges/rspec_binary_search.rb
Created October 17, 2012 21:54
Show Gist options
  • Select an option

  • Save alandotcom/3908531 to your computer and use it in GitHub Desktop.

Select an option

Save alandotcom/3908531 to your computer and use it in GitHub Desktop.
Rspec Binary Search
require './binary'
describe 'binary_search' do
let(:int_ary) { (100..200).to_a }
let(:strg_ary) { %w{ swedish\ chef miss\ piggy scooter gnu animal foo-foo }.sort }
let(:one_elemnt_ary) { [0] }
it 'returns correct index' do
binary_search(135,int_ary).should eq 35
binary_search('miss piggy',strg_ary).should eq 3
binary_search(5,one_elemnt_ary).should eq -1
binary_search(0,one_elemnt_ary).should eq 0
binary_search(0,one_elemnt_ary).should eq 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment