Skip to content

Instantly share code, notes, and snippets.

@mhriess
Forked from dbc-challenges/rspec_binary_search.rb
Created October 19, 2012 04:38
Show Gist options
  • Save mhriess/3916266 to your computer and use it in GitHub Desktop.
Save mhriess/3916266 to your computer and use it in GitHub Desktop.
Rspec Binary Search
require 'simplecov'
SimpleCov.start
require './binary_search.rb'
describe "#binary_search" do
let(:array_1) { [1,2,3,4,5,6,7] }
let(:array_2) { ["apple", "pear", "banana", "pineapple", "kiwi"].sort}
it "is defined as a method" do
defined?(binary_search).should eq 'method'
end
it "requires two arguments" do
method(:binary_search).arity.should eq 2
end
it "returns the correct value for a simple array of numbers" do
binary_search(4, array_1).should eq 3
end
it "returns the correct value for an array of strings" do
binary_search("pear", array_2).should eq 3
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment