Created
September 25, 2008 16:16
-
-
Save Sixeight/12846 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
require 'mini/spec' | |
Mini::Test.autorun | |
class EmptyStackError < StandardError; end | |
class Stack | |
def initialize | |
@stack = [] | |
end | |
def empty? | |
@stack.empty? | |
end | |
def push(obj) | |
@stack << obj | |
end | |
def pop | |
if @stack.size == 0 | |
raise EmptyStackError | |
else | |
@stack.pop | |
end | |
end | |
end | |
describe 'Make empty stack' do | |
before do | |
@obj = Object.new | |
@stack = Stack.new | |
end | |
it 'should be empty' do | |
@stack.empty?.must_equal true | |
end | |
it 'can push object' do | |
@stack.push @obj | |
@stack.empty?.must_equal false | |
end | |
it 'can pop object' do | |
@stack.push @obj | |
@stack.pop.must_equal @obj | |
end | |
it 'should failurer pop when stack empty' do | |
lambda { @stack.pop }.must_raise EmptyStackError | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment