Sha256: e6166288af1274539ec1ab309bb3536c6944ee3605590dfe51e9ff7312b54965

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
# for lib/facets/more/coroutine.rb
#
# Extracted Fri Feb 16 02:00:36 EST 2007
# Project.rb Test Extraction
#

require 'facets/more/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

1 entries across 1 versions & 1 rubygems

Version Path
facets-1.8.49 test/lib/facets/more/test_coroutine.rb