-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathrecursion_test.rb
More file actions
50 lines (37 loc) · 1.27 KB
/
recursion_test.rb
File metadata and controls
50 lines (37 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require 'minitest/autorun'
require 'minitest/reporters'
require "minitest/skip_dsl"
require_relative 'recursion'
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
describe 'linear search' do
let(:list1) { [1, 2, 3] }
let(:empty_list) { [] }
let(:list2) { [1,2,3,4,5,6] }
it 'can find an element in a list' do
expect(linear_search(2, list1)).must_equal 1
expect(linear_search(6, list2)).must_equal 5
end
it 'will return false if it can\'t find the element' do
expect(linear_search(27, list1)).must_equal(-1)
expect(linear_search(-1, list2)).must_equal(-1)
end
it 'will return false finding an item in an empty list' do
expect(linear_search(27, empty_list)).must_equal(-1)
end
end
describe 'binary search' do
let(:list1) { [1, 2, 3] }
let(:empty_list) { [] }
let(:list2) { [1,2,3,4,5,6] }
it 'can find an element in a list' do
expect(binary_search(2, list1)).must_equal 1
expect(binary_search(6, list2)).must_equal 5
end
it 'will return false if it can\'t find the element' do
expect(binary_search(27, list1)).must_equal(-1)
expect(binary_search(-1, list2)).must_equal(-1)
end
it 'will return false finding an item in an empty list' do
expect(binary_search(27, empty_list)).must_equal(-1)
end
end