Skip to content

Instantly share code, notes, and snippets.

@Sixeight
Created September 25, 2008 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sixeight/12846 to your computer and use it in GitHub Desktop.
Save Sixeight/12846 to your computer and use it in GitHub Desktop.
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