Skip to content

Instantly share code, notes, and snippets.

@Sixeight
Created September 21, 2008 04:04
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/11836 to your computer and use it in GitHub Desktop.
Save Sixeight/11836 to your computer and use it in GitHub Desktop.
require 'test/unit'
require 'stack'
class TestStack < Test::Unit::TestCase
def setup
@stack = Stack.new
end
def test_empty?
assert(@stack.empty?)
end
def test_push_pop_3
@stack.push 3
assert_equal(3, @stack.pop)
end
def test_push_pop_1
@stack.push 1
assert_equal(1, @stack.pop)
end
def test_push_pop_empty
@stack.push 2
assert(!@stack.empty?)
@stack.pop
assert(@stack.empty?)
end
def test_zero_pop
assert_raise(EmptyStackError) do
@stack.pop
end
end
def test_stack_size
@stack.push 5
assert_equal(1, @stack.size)
end
def test_stack_size_2
@stack.push 1
@stack.push 2
assert_equal(2, @stack.size)
end
def test_stack_size_0
assert_equal(0, @stack.size)
end
def test_push_pop_empty_again
assert_raise(EmptyStackError) do
@stack.push 1
assert_equal(1, @stack.size)
@stack.push 2
assert_equal(2, @stack.size)
@stack.push 3
assert_equal(3, @stack.size)
assert_equal(3, @stack.pop)
assert_equal(2, @stack.size)
assert_equal(2, @stack.pop)
assert_equal(1, @stack.size)
assert_equal(1, @stack.pop)
assert_equal(0, @stack.size)
@stack.pop
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment