File: test.rb

package info (click to toggle)
libprogressbar-ruby 0.8-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 48 kB
  • ctags: 25
  • sloc: ruby: 219; makefile: 45
file content (62 lines) | stat: -rw-r--r-- 1,046 bytes parent folder | download | duplicates (2)
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
require 'progressbar'

total = 100
pbar = ProgressBar.new("test(inc)", total)
total.times {
  sleep(0.02)
  pbar.inc
}
pbar.finish

total = 1000
pbar = ProgressBar.new("test(set)", total)
(1..total).find_all {|x| x % 10 == 0}.each {|x|
  sleep(0.02)
  pbar.set(x)
}
pbar.finish

total = File.size("progressbar.rb")
pbar = ProgressBar.new("test(inc(x))", total)
File.new("progressbar.rb").each {|line|
  sleep(0.02)
  pbar.inc(line.length)
}
pbar.finish

total = 0
pbar = ProgressBar.new("test(total=0)", total)
pbar.finish

total = 100
pbar = ProgressBar.new("test(halt)", total)
(total / 2).times {
  sleep(0.02)
  pbar.inc
}
pbar.halt

total = 1024 * 1024
pbar = ProgressBar.new("test(bytes)", total)
pbar.file_transfer_mode
0.step(total, 2048) {|x|
  pbar.set(x)
  sleep(0.01)
}
pbar.finish

total = 100000
pbar = ProgressBar.new("test(slow)", total)
0.step(500, 1) {|x|
  pbar.set(x)
  sleep(0.01)
}
pbar.halt

total = 100
pbar = ProgressBar.new("test(invalid set)", total)
begin
  pbar.set(200)
rescue RuntimeError => e
  puts e.message
end