PageRenderTime 55ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/mediashelf/fedora-migrator
Ruby | 55 lines | 35 code | 10 blank | 10 comment | 0 complexity | b05ac7e33d587ba6849bd3be6f6cce7e MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
  1. # Test facets/timer.rb
  2. require 'facets/timer.rb'
  3. require 'test/unit'
  4. class TC_Timer < Test::Unit::TestCase
  5. def test_timed
  6. timed { |timer|
  7. assert_equal 0, timer.total_time.round
  8. sleep 1
  9. assert_equal 1, timer.total_time.round
  10. timer.stop
  11. assert_equal 1, timer.total_time.round
  12. sleep 1
  13. assert_equal 1, timer.total_time.round
  14. timer.start
  15. assert_equal 1, timer.total_time.round
  16. sleep 1
  17. assert_equal 2, timer.total_time.round
  18. }
  19. end
  20. def test_outoftime
  21. t = Timer.new(1)
  22. assert_raises( TimeoutError ) {
  23. t.start
  24. sleep 2
  25. t.stop
  26. }
  27. end
  28. # This has been removed becuase it is too close to call.
  29. # Sometimes and error is returned sometimes it is not.
  30. #def test_nickoftime
  31. # assert_raises( TimeoutError ) {
  32. # @t.start
  33. # sleep 2
  34. # @t.stop
  35. # }
  36. #end
  37. def test_intime
  38. t = Timer.new(2)
  39. assert_nothing_raised {
  40. t.start
  41. sleep 1
  42. t.stop
  43. }
  44. end
  45. end