]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blob - lib/ruby-progressbar/test.rb
Update the makefile to build/install a gem.
[dead/whatever-dl.git] / lib / ruby-progressbar / test.rb
1 require 'test/unit'
2
3 # Modified a little to run from the whatever-dl test suite.
4 require (File.dirname(__FILE__) + '/progressbar')
5
6 class ProgressBarTest < Test::Unit::TestCase
7 SleepUnit = 0.01
8
9 def do_make_progress_bar (title, total)
10 ProgressBar.new(title, total)
11 end
12
13 def test_bytes
14 total = 1024 * 1024
15 pbar = do_make_progress_bar("test(bytes)", total)
16 pbar.file_transfer_mode
17 0.step(total, 2**14) {|x|
18 pbar.set(x)
19 sleep(SleepUnit)
20 }
21 pbar.finish
22 end
23
24 def test_clear
25 total = 100
26 pbar = do_make_progress_bar("test(clear)", total)
27 total.times {
28 sleep(SleepUnit)
29 pbar.inc
30 }
31 pbar.clear
32 puts
33 end
34
35 def test_halt
36 total = 100
37 pbar = do_make_progress_bar("test(halt)", total)
38 (total / 2).times {
39 sleep(SleepUnit)
40 pbar.inc
41 }
42 pbar.halt
43 end
44
45 def test_inc
46 total = 100
47 pbar = do_make_progress_bar("test(inc)", total)
48 total.times {
49 sleep(SleepUnit)
50 pbar.inc
51 }
52 pbar.finish
53 end
54
55 def test_inc_x
56 # Modified a little to run from the whatever-dl test suite.
57 pbar_file_path = (File.dirname(__FILE__) + '/progressbar.rb')
58
59 total = File.size(pbar_file_path)
60 pbar = do_make_progress_bar("test(inc(x))", total)
61 File.new(pbar_file_path).each {|line|
62 sleep(SleepUnit)
63 pbar.inc(line.length)
64 }
65 pbar.finish
66 end
67
68 def test_invalid_set
69 total = 100
70 pbar = do_make_progress_bar("test(invalid set)", total)
71 begin
72 pbar.set(200)
73 rescue RuntimeError => e
74 puts e.message
75 end
76 end
77
78 def test_set
79 total = 1000
80 pbar = do_make_progress_bar("test(set)", total)
81 (1..total).find_all {|x| x % 10 == 0}.each {|x|
82 sleep(SleepUnit)
83 pbar.set(x)
84 }
85 pbar.finish
86 end
87
88 def test_slow
89 total = 100000
90 pbar = do_make_progress_bar("test(slow)", total)
91 0.step(500, 1) {|x|
92 pbar.set(x)
93 sleep(SleepUnit)
94 }
95 pbar.halt
96 end
97
98 def test_total_zero
99 total = 0
100 pbar = do_make_progress_bar("test(total=0)", total)
101 pbar.finish
102 end
103 end
104
105 class ReversedProgressBarTest < ProgressBarTest
106 def do_make_progress_bar (title, total)
107 ReversedProgressBar.new(title, total)
108 end
109 end
110