Class: UploadProgressTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- UploadProgressTest
- Defined in:
- lib/upload_progress/test/upload_progress_testx.rb
Instance Method Summary collapse
- #test_elapsed ⇒ Object
- #test_finished ⇒ Object
- #test_overflow ⇒ Object
- #test_rapid_samples ⇒ Object
- #test_remaining ⇒ Object
- #test_stalled ⇒ Object
- #test_zero ⇒ Object
Instance Method Details
#test_elapsed ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/upload_progress/test/upload_progress_testx.rb', line 34 def test_elapsed progress = new_progress(10000) (1..5).each do |t| progress.update!(1000, Float(t)) end assert_in_delta(5.0, progress.elapsed_seconds, 0.001) assert_equal(10000, progress.total_bytes) assert_equal(5000, progress.received_bytes) assert_equal(5000, progress.remaining_bytes) end |
#test_finished ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/upload_progress/test/upload_progress_testx.rb', line 62 def test_finished progress = new_progress(10000) (1..9).each do |t| progress.update!(1000, Float(t)) assert_equal(false, progress.finished?) assert_equal(1000.0, progress.bitrate) assert_equal(false, progress.stalled?) end assert_equal(false, progress.finished?) progress.update!(1000, 10.0) assert_equal(true, progress.finished?) end |
#test_overflow ⇒ Object
45 46 47 48 49 |
# File 'lib/upload_progress/test/upload_progress_testx.rb', line 45 def test_overflow progress = new_progress(10000) progress.update!(20000, 1.0) assert_equal(10000, progress.received_bytes) end |
#test_rapid_samples ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/upload_progress/test/upload_progress_testx.rb', line 75 def test_rapid_samples progress = new_progress(10000) (1..1000).each do |t| progress.update!(10, t/100.0) end assert_in_delta(1000.0, progress.bitrate, 0.001) assert_equal(true, progress.finished?) end |
#test_remaining ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/upload_progress/test/upload_progress_testx.rb', line 6 def test_remaining progress = new_progress(20000) assert_equal(0, progress.received_bytes) assert_equal(20000, progress.remaining_bytes) progress.update!(10000, 1.0) assert_equal(10000, progress.remaining_bytes) assert_equal(1.0, progress.remaining_seconds) assert_equal(50, progress.completed_percent) assert_equal(true, progress.started?) assert_equal(false, progress.finished?) assert_equal(false, progress.stalled?) progress.update!(10000, 2.0) assert_equal(true, progress.finished?) assert_equal(0.0, progress.remaining_seconds) end |
#test_stalled ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/upload_progress/test/upload_progress_testx.rb', line 22 def test_stalled progress = new_progress(10000) assert_equal(false, progress.stalled?) progress.update!(100, 1.0) assert_equal(false, progress.stalled?) progress.update!(100, 20.0) assert_equal(true, progress.stalled?) assert_in_delta(0.0, progress.bitrate, 0.001) progress.update!(100, 21.0) assert_equal(false, progress.stalled?) end |
#test_zero ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/upload_progress/test/upload_progress_testx.rb', line 51 def test_zero progress = new_progress(0) assert_equal(0, progress.total_bytes) assert_equal(0, progress.remaining_bytes) assert_equal(false, progress.started?) assert_equal(true, progress.finished?) assert_equal(0, progress.bitrate) assert_equal(0, progress.completed_percent) assert_equal(0, progress.remaining_seconds) end |