Skip to content

Instantly share code, notes, and snippets.

@sflinter
Created February 8, 2013 14:32
Show Gist options
  • Save sflinter/4739348 to your computer and use it in GitHub Desktop.
Save sflinter/4739348 to your computer and use it in GitHub Desktop.
require 'test/unit'
require './queue'
class TestQueue < Test::Unit::TestCase
def setup
@q = Queue.new
end
def test_should_create_a_new_queue
assert @q
end
def test_should_create_empty_queue
assert_equal 0, @q.size
end
def test_should_add_a_node
@q.push("random object")
assert_equal 1, @q.size
end
def test_should_add_two_nodes
@q.push("random object")
@q.push("another random object")
assert_equal 2, @q.size
end
def test_should_add_random_bunch_of_nodes
i = Random.rand(1000)
i.times { @q.push(i.to_s) }
assert_equal i, @q.size
i.times { assert_equal i.to_s, @q.pop }
end
def test_should_return_a_node
@q.push("random object")
o = @q.pop
assert_equal "random object", o
end
def test_should_return_a_random_object
t = Time.now
@q.push(t)
o = @q.pop
assert_equal t, o
end
def test_should_shrink_after_pop
@q.push("random object")
o = @q.pop
assert_equal 0, @q.size
end
def test_should_raise_exception_after_empty_pop
exception = assert_raise(EmptyQueueError) { @q.pop }
assert_equal "Empty queue", exception.message
end
def test_should_still_work_after_empty_pop
begin
@q.pop
rescue EmptyQueueError
@q.push("Another random string")
assert_equal 1, @q.size
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment