PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/gems/facets-2.4.5/test/more/test_coroutine.rb

https://bitbucket.org/mediashelf/fedora-migrator
Ruby | 46 lines | 36 code | 9 blank | 1 comment | 1 complexity | 91c24e8038c073f9f01e215e1fb6aac4 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
  1. # Test facets/coroutine.rb
  2. require 'facets/coroutine.rb'
  3. require 'test/unit'
  4. class TC_Coroutine < Test::Unit::TestCase
  5. def test_run
  6. assert_nothing_raised {
  7. count = 100
  8. input = (1..count).map { (rand * 10000).round.to_f / 100 }
  9. @producer = Coroutine.new do |me|
  10. loop do
  11. 1.upto(6) do
  12. me[:last_input] = input.shift
  13. me.resume(@printer)
  14. end
  15. input.shift # discard every seventh input number
  16. end
  17. end
  18. @printer = Coroutine.new do |me|
  19. loop do
  20. 1.upto(8) do
  21. me.resume(@producer)
  22. if @producer[:last_input]
  23. @producer[:last_input] = nil
  24. end
  25. me.resume(@controller)
  26. end
  27. end
  28. end
  29. @controller = Coroutine.new do |me|
  30. until input.empty? do
  31. me.resume(@printer)
  32. end
  33. end
  34. @controller.run
  35. }
  36. end
  37. end