Class: ProgressBarTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/vendor/ruby-progressbar-0.9/lib/test.rb

Direct Known Subclasses

ReversedProgressBarTest

Constant Summary collapse

SleepUnit =
0.01

Instance Method Summary collapse

Instance Method Details

#do_make_progress_bar(title, total) ⇒ Object



7
8
9
# File 'lib/vendor/ruby-progressbar-0.9/lib/test.rb', line 7

def do_make_progress_bar (title, total)
  ProgressBar.new(title, total)
end

#test_bytesObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/vendor/ruby-progressbar-0.9/lib/test.rb', line 11

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

#test_clearObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/vendor/ruby-progressbar-0.9/lib/test.rb', line 22

def test_clear
  total = 100
  pbar = do_make_progress_bar("test(clear)", total)
  total.times {
    sleep(SleepUnit)
    pbar.inc
  }
  pbar.clear
  puts
end

#test_haltObject



33
34
35
36
37
38
39
40
41
# File 'lib/vendor/ruby-progressbar-0.9/lib/test.rb', line 33

def test_halt
  total = 100
  pbar = do_make_progress_bar("test(halt)", total)
  (total / 2).times {
    sleep(SleepUnit)
    pbar.inc
  }
  pbar.halt
end

#test_incObject



43
44
45
46
47
48
49
50
51
# File 'lib/vendor/ruby-progressbar-0.9/lib/test.rb', line 43

def test_inc
  total = 100
  pbar = do_make_progress_bar("test(inc)", total)
  total.times {
    sleep(SleepUnit)
    pbar.inc
  }
  pbar.finish
end

#test_inc_xObject



53
54
55
56
57
58
59
60
61
# File 'lib/vendor/ruby-progressbar-0.9/lib/test.rb', line 53

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

#test_invalid_setObject



63
64
65
66
67
68
69
70
71
# File 'lib/vendor/ruby-progressbar-0.9/lib/test.rb', line 63

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

#test_setObject



73
74
75
76
77
78
79
80
81
# File 'lib/vendor/ruby-progressbar-0.9/lib/test.rb', line 73

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

#test_slowObject



83
84
85
86
87
88
89
90
91
# File 'lib/vendor/ruby-progressbar-0.9/lib/test.rb', line 83

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

#test_total_zeroObject



93
94
95
96
97
# File 'lib/vendor/ruby-progressbar-0.9/lib/test.rb', line 93

def test_total_zero
  total = 0
  pbar = do_make_progress_bar("test(total=0)", total)
  pbar.finish
end