/vendor/gems/facets-2.4.5/test/more/test_timer.rb
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
- # Test facets/timer.rb
- require 'facets/timer.rb'
- require 'test/unit'
- class TC_Timer < Test::Unit::TestCase
- def test_timed
- timed { |timer|
- assert_equal 0, timer.total_time.round
- sleep 1
- assert_equal 1, timer.total_time.round
- timer.stop
- assert_equal 1, timer.total_time.round
- sleep 1
- assert_equal 1, timer.total_time.round
- timer.start
- assert_equal 1, timer.total_time.round
- sleep 1
- assert_equal 2, timer.total_time.round
- }
- end
- def test_outoftime
- t = Timer.new(1)
- assert_raises( TimeoutError ) {
- t.start
- sleep 2
- t.stop
- }
- end
- # This has been removed becuase it is too close to call.
- # Sometimes and error is returned sometimes it is not.
- #def test_nickoftime
- # assert_raises( TimeoutError ) {
- # @t.start
- # sleep 2
- # @t.stop
- # }
- #end
- def test_intime
- t = Timer.new(2)
- assert_nothing_raised {
- t.start
- sleep 1
- t.stop
- }
- end
- end