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.19.36 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.35 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.34 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.32 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.31 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.30 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.29 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.28 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.27 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.26 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.25 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.24 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.23 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.22 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.21 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.20 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.19 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.18 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.17 test/rbbt/util/log/test_progress.rb
rbbt-util-5.19.16 test/rbbt/util/log/test_progress.rb