Sha256: f7c7563db991e26a1150488fbfc8a59218fe203f1f769144c1627216108ec4bd

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

require 'test/unit'
require '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
end

class ReversedProgressBarTest < ProgressBarTest
  def do_make_progress_bar (title, total)
    ReversedProgressBar.new(title, total)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
Flucti-flucti-cli-0.1.16 lib/vendor/ruby-progressbar-0.9/lib/test.rb