Sha256: 71df046612e0eaf3b05702e792fb818ecfad1383d5c9533e43a4884bc577c22d

Contents?: true

Size: 1.84 KB

Versions: 377

Compression:

Stored size: 1.84 KB

Contents

require File.join(File.expand_path(File.dirname(__FILE__)), '../../..', 'test_helper.rb')
require 'rbbt/util/log/progress'

class TestProgress < Test::Unit::TestCase
  def test_bar
    t1 = Thread.new do
      Log::ProgressBar.with_bar(20, :desc => "Bar 1") do |bar|
        20.times do
          bar.tick
          sleep 0.3
        end
        Log.debug "Done progress"
        assert_equal 100, bar.percent
      end
    end

    t2 = Thread.new do
      Log::ProgressBar.with_bar(20, :desc => "Bar 2") do |bar|
        20.times do
          bar.tick
          sleep 0.2
        end
        Log.debug "Done progress"
        assert_equal 100, bar.percent
      end
    end
    t1.join
    t2.join
  end

  def test_bar_no_size
    t1 = Thread.new do
      Log::ProgressBar.with_bar(nil, :desc => "Bar 1") do |bar|
        20.times do
          bar.tick
          sleep 0.3
        end
        #Log.debug "Done progress"
        assert bar.history.length > 0
      end
    end

    t2 = Thread.new do
      Log::ProgressBar.with_bar(nil, :desc => "Bar 2") do |bar|
        20.times do
          bar.tick
          sleep 0.2
        end
        #Log.debug "Done progress"
        assert bar.history.length > 0
      end
    end
    t1.join
    t2.join
  end

  def test_bar_nested
    Log::ProgressBar.with_bar(20, :desc => "Bar 1") do |bar|
      bar.init
      20.times do
        Log::ProgressBar.with_bar(5, :desc => "Bar 2") do |bar|
          5.times do
            bar.tick
            sleep 0.2
          end
        end
        bar.tick
        sleep 0.2
      end
    end
  end

  def test_pos
    size = 10000

    Log::ProgressBar.with_bar(size, :desc => "Bar 1") do |bar|
      bar.init
      nums = []
      100.times do
        nums << rand(size)
      end
      nums.sort.each do |num|
        bar.pos num
        sleep 0.1
      end
      bar.tick
    end
  end

end

Version data entries

377 entries across 377 versions & 1 rubygems

Version Path
rbbt-util-5.34.17 test/rbbt/util/log/test_progress.rb
rbbt-util-5.34.16 test/rbbt/util/log/test_progress.rb
rbbt-util-5.34.15 test/rbbt/util/log/test_progress.rb
rbbt-util-5.34.14 test/rbbt/util/log/test_progress.rb
rbbt-util-5.34.13 test/rbbt/util/log/test_progress.rb
rbbt-util-5.34.12 test/rbbt/util/log/test_progress.rb
rbbt-util-5.34.11 test/rbbt/util/log/test_progress.rb
rbbt-util-5.34.10 test/rbbt/util/log/test_progress.rb
rbbt-util-5.34.9 test/rbbt/util/log/test_progress.rb
rbbt-util-5.34.8 test/rbbt/util/log/test_progress.rb
rbbt-util-5.34.7 test/rbbt/util/log/test_progress.rb
rbbt-util-5.34.5 test/rbbt/util/log/test_progress.rb
rbbt-util-5.34.4 test/rbbt/util/log/test_progress.rb
rbbt-util-5.34.3 test/rbbt/util/log/test_progress.rb
rbbt-util-5.34.2 test/rbbt/util/log/test_progress.rb
rbbt-util-5.34.1 test/rbbt/util/log/test_progress.rb
rbbt-util-5.34.0 test/rbbt/util/log/test_progress.rb
rbbt-util-5.33.21 test/rbbt/util/log/test_progress.rb
rbbt-util-5.33.20 test/rbbt/util/log/test_progress.rb
rbbt-util-5.33.19 test/rbbt/util/log/test_progress.rb