forked from neilparikh/ruby-linked-list
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.rb
61 lines (52 loc) · 1.39 KB
/
test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require './linked_list'
require 'test/unit'
class TestLinkedList < Test::Unit::TestCase
def test_create_new_list
@list = List.new(1)
assert_equal([1], @list.to_a)
end
def test_push
@list = List.new(1)
@list.push(2)
assert_equal([1, 2], @list.to_a)
end
def test_pop_multiple_elements
# pops from an list with more than one element
@list = List.new(1, 2, 3)
assert_equal(3, @list.pop)
assert_equal([1, 2], @list.to_a)
end
def test_pop_one_element
@list = List.new(1)
# pops from an list with one element
assert_equal(1, @list.pop)
assert_equal([], @list.to_a)
end
def test_pop_zero_elements
# pops from an list with zero elements
@list = List.new
assert_raise(RuntimeError) { @list.pop }
end
def test_unshift
@list = List.new(1)
@list.unshift(0)
assert_equal([0,1], @list.to_a)
end
def test_shift_multiple_elements
# shifts from an list with more than one element
@list = List.new(1, 3, 4)
assert_equal(1, @list.shift)
assert_equal([3, 4], @list.to_a)
end
def test_shift_one_element
@list = List.new(1)
# shifts from an list with one element
assert_equal(1, @list.shift)
assert_equal([], @list.to_a)
end
def test_shift_zero_elements
# shifts from an list with zero elements
@list = List.new
assert_raise(RuntimeError) { @list.shift }
end
end