Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Correctly returns a snapshot of the data in the queue

* Fixes #4
commit f0e2a1ec9e2b49d3d9f08662d35b7c9fb45f57a7 1 parent 69ae46f
@alindeman authored
Showing with 15 additions and 1 deletion.
  1. +4 −1 lib/circular_queue.rb
  2. +11 −0 spec/circular_queue_spec.rb
View
5 lib/circular_queue.rb
@@ -138,7 +138,10 @@ def num_waiting
# Allows for easy iteration of queue from front to back
def data
@mutex.synchronize do
- @data.clone.rotate @front
+ @data.clone.tap do |data|
+ data.rotate!(@front)
+ data.slice!(@size..-1)
+ end
end
end
View
11 spec/circular_queue_spec.rb
@@ -120,4 +120,15 @@
subject.size.should be_zero
end
end
+
+ describe "data" do
+ it "allows taking a snapshot of the data in the queue" do
+ subject.enq(1)
+ subject.enq(2)
+ subject.enq(3)
+ subject.deq
+
+ subject.data.should == [2, 3]
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.