mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
75bfc6440d
commit
1d15d5f080
4370 changed files with 0 additions and 0 deletions
10
spec/ruby/library/thread/shared/queue/clear.rb
Normal file
10
spec/ruby/library/thread/shared/queue/clear.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
describe :queue_clear, shared: true do
|
||||
it "removes all objects from the queue" do
|
||||
queue = @object.call
|
||||
queue << Object.new
|
||||
queue << 1
|
||||
queue.empty?.should be_false
|
||||
queue.clear
|
||||
queue.empty?.should be_true
|
||||
end
|
||||
end
|
26
spec/ruby/library/thread/shared/queue/close.rb
Normal file
26
spec/ruby/library/thread/shared/queue/close.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
describe :queue_close, shared: true do
|
||||
it "closes the queue and returns nil for further #pop" do
|
||||
q = @object.call
|
||||
q << 1
|
||||
q.close
|
||||
q.pop.should == 1
|
||||
q.pop.should == nil
|
||||
q.pop.should == nil
|
||||
end
|
||||
|
||||
it "prevents further #push" do
|
||||
q = @object.call
|
||||
q.close
|
||||
lambda {
|
||||
q << 1
|
||||
}.should raise_error(ClosedQueueError)
|
||||
end
|
||||
|
||||
it "may be called multiple times" do
|
||||
q = @object.call
|
||||
q.close
|
||||
q.closed?.should be_true
|
||||
q.close # no effect
|
||||
q.closed?.should be_true
|
||||
end
|
||||
end
|
12
spec/ruby/library/thread/shared/queue/closed.rb
Normal file
12
spec/ruby/library/thread/shared/queue/closed.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
describe :queue_closed?, shared: true do
|
||||
it "returns false initially" do
|
||||
queue = @object.call
|
||||
queue.closed?.should be_false
|
||||
end
|
||||
|
||||
it "returns true when the queue is closed" do
|
||||
queue = @object.call
|
||||
queue.close
|
||||
queue.closed?.should be_true
|
||||
end
|
||||
end
|
37
spec/ruby/library/thread/shared/queue/deque.rb
Normal file
37
spec/ruby/library/thread/shared/queue/deque.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
describe :queue_deq, shared: true do
|
||||
it "removes an item from the Queue" do
|
||||
q = @object.call
|
||||
q << Object.new
|
||||
q.size.should == 1
|
||||
q.send(@method)
|
||||
q.size.should == 0
|
||||
end
|
||||
|
||||
it "returns items in the order they were added" do
|
||||
q = @object.call
|
||||
q << 1
|
||||
q << 2
|
||||
q.send(@method).should == 1
|
||||
q.send(@method).should == 2
|
||||
end
|
||||
|
||||
it "blocks the thread until there are items in the queue" do
|
||||
q = @object.call
|
||||
v = 0
|
||||
|
||||
th = Thread.new do
|
||||
q.send(@method)
|
||||
v = 1
|
||||
end
|
||||
|
||||
v.should == 0
|
||||
q << Object.new
|
||||
th.join
|
||||
v.should == 1
|
||||
end
|
||||
|
||||
it "raises a ThreadError if Queue is empty" do
|
||||
q = @object.call
|
||||
lambda { q.send(@method,true) }.should raise_error(ThreadError)
|
||||
end
|
||||
end
|
12
spec/ruby/library/thread/shared/queue/empty.rb
Normal file
12
spec/ruby/library/thread/shared/queue/empty.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
describe :queue_empty?, shared: true do
|
||||
it "returns true on an empty Queue" do
|
||||
queue = @object.call
|
||||
queue.empty?.should be_true
|
||||
end
|
||||
|
||||
it "returns false when Queue is not empty" do
|
||||
queue = @object.call
|
||||
queue << Object.new
|
||||
queue.empty?.should be_false
|
||||
end
|
||||
end
|
10
spec/ruby/library/thread/shared/queue/enque.rb
Normal file
10
spec/ruby/library/thread/shared/queue/enque.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
describe :queue_enq, shared: true do
|
||||
it "adds an element to the Queue" do
|
||||
q = @object.call
|
||||
q.size.should == 0
|
||||
q.send(@method, Object.new)
|
||||
q.size.should == 1
|
||||
q.send(@method, Object.new)
|
||||
q.size.should == 2
|
||||
end
|
||||
end
|
9
spec/ruby/library/thread/shared/queue/length.rb
Normal file
9
spec/ruby/library/thread/shared/queue/length.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
describe :queue_length, shared: true do
|
||||
it "returns the number of elements" do
|
||||
q = @object.call
|
||||
q.send(@method).should == 0
|
||||
q << Object.new
|
||||
q << Object.new
|
||||
q.send(@method).should == 2
|
||||
end
|
||||
end
|
16
spec/ruby/library/thread/shared/queue/num_waiting.rb
Normal file
16
spec/ruby/library/thread/shared/queue/num_waiting.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
describe :queue_num_waiting, shared: true do
|
||||
it "reports the number of threads waiting on the queue" do
|
||||
q = @object.call
|
||||
threads = []
|
||||
|
||||
5.times do |i|
|
||||
q.num_waiting.should == i
|
||||
t = Thread.new { q.deq }
|
||||
Thread.pass until q.num_waiting == i+1
|
||||
threads << t
|
||||
end
|
||||
|
||||
threads.each { q.enq Object.new }
|
||||
threads.each {|t| t.join }
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue