forked from jfelchner/ruby-progressbar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.rb
116 lines (102 loc) · 2.17 KB
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
require 'test/unit'
require 'lib/progressbar'
class ProgressBarTest < Test::Unit::TestCase
SleepUnit = 0.01
def do_make_progress_bar (title, total)
ProgressBar.new(title, total)
end
def test_bytes
total = 1024 * 1024
pbar = do_make_progress_bar("test(bytes)", total)
pbar.file_transfer_mode
0.step(total, 2**14) {|x|
pbar.set(x)
sleep(SleepUnit)
}
pbar.finish
end
def test_clear
total = 100
pbar = do_make_progress_bar("test(clear)", total)
total.times {
sleep(SleepUnit)
pbar.inc
}
pbar.clear
puts
end
def test_halt
total = 100
pbar = do_make_progress_bar("test(halt)", total)
(total / 2).times {
sleep(SleepUnit)
pbar.inc
}
pbar.halt
end
def test_inc
total = 100
pbar = do_make_progress_bar("test(inc)", total)
total.times {
sleep(SleepUnit)
pbar.inc
}
pbar.finish
end
def test_inc_x
total = File.size("progressbar.rb")
pbar = do_make_progress_bar("test(inc(x))", total)
File.new("progressbar.rb").each {|line|
sleep(SleepUnit)
pbar.inc(line.length)
}
pbar.finish
end
def test_invalid_set
total = 100
pbar = do_make_progress_bar("test(invalid set)", total)
begin
pbar.set(200)
rescue RuntimeError => e
puts e.message
end
end
def test_set
total = 1000
pbar = do_make_progress_bar("test(set)", total)
(1..total).find_all {|x| x % 10 == 0}.each {|x|
sleep(SleepUnit)
pbar.set(x)
}
pbar.finish
end
def test_slow
total = 100000
pbar = do_make_progress_bar("test(slow)", total)
0.step(500, 1) {|x|
pbar.set(x)
sleep(SleepUnit)
}
pbar.halt
end
def test_total_zero
total = 0
pbar = do_make_progress_bar("test(total=0)", total)
pbar.finish
end
def test_alternate_bar
total = 100
pbar = do_make_progress_bar("test(alternate)", total)
pbar.bar_mark = "="
total.times {
sleep(SleepUnit)
pbar.inc
}
pbar.finish
end
end
class ReversedProgressBarTest < ProgressBarTest
def do_make_progress_bar (title, total)
ReversedProgressBar.new(title, total)
end
end