Sha256: ae03ac71bca9e9018dc463deaa1ab4c3d14c0a8b3509f4c075385267d8575841

Contents?: true

Size: 944 Bytes

Versions: 15

Compression:

Stored size: 944 Bytes

Contents

# Test facets/coroutine.rb

require 'facets/coroutine.rb'
require 'test/unit'

class TC_Coroutine < Test::Unit::TestCase

  def test_run
    assert_nothing_raised {

      count = 100
      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]
              @producer[:last_input] = nil
            end
            me.resume(@controller)
          end
        end
      end

      @controller = Coroutine.new do |me|
        until input.empty? do
          me.resume(@printer)
        end
      end
      @controller.run

    }
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
facets-2.7.0 test/more/test_coroutine.rb
facets-2.6.0 test/more/test_coroutine.rb
facets-2.2.0 test/unit/test_coroutine.rb
facets-2.2.1 test/unit/test_coroutine.rb
facets-2.3.0 test/class/test_coroutine.rb
facets-2.4.0 test/test_coroutine.rb
facets-2.1.3 test/unit/test_coroutine.rb
facets-2.4.1 test/test_coroutine.rb
facets-2.4.3 test/more/test_coroutine.rb
facets-2.4.2 test/more/test_coroutine.rb
facets-2.4.4 test/more/test_coroutine.rb
facets-2.5.0 test/more/test_coroutine.rb
facets-2.4.5 test/more/test_coroutine.rb
facets-2.5.1 test/more/test_coroutine.rb
facets-2.5.2 test/more/test_coroutine.rb