Created
May 23, 2010 04:21
-
-
Save louis-wu/410631 to your computer and use it in GitHub Desktop.
This file contains 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
class Stack | |
attr_reader :stack | |
def initialize | |
@stack = [] | |
end | |
def peek(obj) | |
@stack.push(obj) | |
end | |
def pop | |
@stack.pop | |
end | |
end |
This file contains 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 Stack do | |
before(:each) do | |
@stack = Stack.new | |
@stack.push :item | |
end | |
describe "#peek" do | |
it "should return the top element" do | |
@stack.peek.should == :item | |
end | |
it "should not remove the top element" do | |
@stack.peek | |
@stack.size.should == 1 | |
end | |
end | |
describe "#pop" do | |
it "should return the top element" do | |
@stack.pop.should == :item | |
end | |
it "should remove the top element" do | |
@stack.pop | |
@stack.size.should == 0 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment