-
-
Save kylessnell/3913212 to your computer and use it in GitHub Desktop.
Rspec Binary Search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'binatry_search' do | |
let(:test_array_1) { [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] } | |
let(:test_array_2) { (1..100).to_a } | |
let(:test_object_1) { 3 } | |
let(:test_object_2) { 10 } | |
let(:test_object_3) { 39 } | |
let(:test_object_4) { 97 } | |
it 'is defined' do | |
defined?(binary_search).should eq 'method' | |
end | |
it 'requires two arguements' do | |
method(:binary_search).arity.should eq 2 | |
end | |
it 'raises an error if 2nd argument is not an array' do | |
expect { binary_search("a", "b") }.to raise_error | |
end | |
it 'returns the correct object in a small array' do | |
binary_search(test_object_1, test_array_1).should eq 2 | |
binary_search(test_object_2, test_array_1).should eq 9 | |
end | |
it 'returns the correct object in a larger array' do | |
binary_search(test_object_3, test_array_2).should eq 38 | |
binary_search(test_object_4, test_array_2).should eq 96 | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment