Sha256: 5f3ce311344de6b96684426d9cb03a5a1016350bee39f2ee6ad62eb14513dec7
Contents?: true
Size: 1017 Bytes
Versions: 1
Compression:
Stored size: 1017 Bytes
Contents
require 'test/unit' require 'carat/coroutine' class TC_Coroutine < Test::Unit::TestCase def test_run assert_nothing_raised { count = (ARGV.shift || 1000).to_i input = (1..count).map { (rand * 10000).round.to_f / 100} @producer = Coroutine.new do |me| loop do 1.upto(6) do me[:last_input] = input.shift me.resume(@printer) end input.shift # discard every seventh input number end end @printer = Coroutine.new do |me| loop do 1.upto(8) do me.resume(@producer) if @producer[:last_input] #print @producer[:last_input], "\t" @producer[:last_input] = nil end me.resume(@controller) end #puts end end @controller = Coroutine.new do |me| until input.empty? do me.resume(@printer) end end @controller.run puts } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
carats-0.3.0 | test/tc_coroutine.rb |