-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinked_list_spec.rb
40 lines (35 loc) · 951 Bytes
/
linked_list_spec.rb
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
require './linked_list'
describe LinkedList do
let(:list) do
list = LinkedList.new
%w(1 2 3 4 5).each do |el|
list.add_to_list(el)
end
list
end
context 'given a list of elements' do
it 'creates a linked list' do
expect(list.to_s).to eq '1->2->3->4->5'
end
context 'reversing the list' do
context 'recursively' do
it 'correctly reverses the list\'s elements' do
list.reverse_recursive
expect(list.to_s).to eq '5->4->3->2->1'
end
end
context 'iteratively' do
it 'correctly reverses the list\'s elements' do
list.reverse_iterative
expect(list.to_s).to eq '5->4->3->2->1'
end
context 'in place' do
it 'correctly reverses the list\'s elements' do
list.reverse_iterative_in_place
expect(list.to_s).to eq '5->4->3->2->1'
end
end
end
end
end
end