Created
September 21, 2008 04:04
-
-
Save Sixeight/11836 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 '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