forked from kanwei/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_spec.rb
60 lines (47 loc) · 1.13 KB
/
stack_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
$: << File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')
require 'algorithms'
describe "empty stack" do
before(:each) do
@stack = Containers::Stack.new
end
it "should return nil when sent #pop" do
@stack.pop.should be_nil
end
it "should return a size of 1 when sent #push" do
@stack.push(1)
@stack.size.should eql(1)
end
it "should return nil when sent #next" do
@stack.next.should be_nil
end
it "should return empty?" do
@stack.empty?.should be_true
end
end
describe "non-empty stack" do
before(:each) do
@stack = Containers::Stack.new
@stack.push(10)
@stack.push("10")
end
it "should return last pushed object" do
@stack.pop.should eql("10")
end
it "should return the size" do
@stack.size.should eql(2)
end
it "should not return empty?" do
@stack.empty?.should be_false
end
it "should iterate in LIFO order" do
arr = []
@stack.each { |obj| arr << obj }
arr.should eql(["10", 10])
end
it "should return nil after all pops" do
@stack.pop
@stack.pop
@stack.pop.should be_nil
@stack.next.should be_nil
end
end