Sha256: 406a3acab853d7abaccdcb2193f35d018ef3236fa858d4834ffcf3138d1cce87

Contents?: true

Size: 1.56 KB

Versions: 165

Compression:

Stored size: 1.56 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
end

Version data entries

165 entries across 165 versions & 1 rubygems

Version Path
rbbt-util-5.21.59 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.58 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.57 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.56 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.55 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.54 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.53 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.51 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.50 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.49 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.47 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.46 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.45 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.44 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.43 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.42 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.39 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.38 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.37 test/rbbt/util/log/test_progress.rb
rbbt-util-5.21.36 test/rbbt/util/log/test_progress.rb