Sha256: 4805209136429305eeb01f560703d91702987033ac49308e5ed58a7df6515a72

Contents?: true

Size: 779 Bytes

Versions: 4

Compression:

Stored size: 779 Bytes

Contents

require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))



class TestMultithreading < Minitest::Test

  def setup
    initialize_context
  end

  def test_concurrent_precision
    threads = []
    for prec in (5..100)
      threads << Thread.new(prec) do |p|
        n = 10000/(p/3)
        n_fails = 0
        DecNum.local_context do
          DecNum.context.precision = p
          n.times do
            t = (DecNum(1)/DecNum(3)).to_s
            n_fails += 1 if (t.size!=(p+2)) || (DecNum.context.precision!=p)
          end
        end
        Thread.current[:n_fails] = n_fails
      end
    end
    total_fails = 0
    threads.each{|thr| thr.join; total_fails += thr[:n_fails]}
    assert total_fails==0,"Context precision different per thread"
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
flt-1.5.4 test/test_multithreading.rb
flt-1.5.3 test/test_multithreading.rb
flt-1.5.2 test/test_multithreading.rb
flt-1.5.1 test/test_multithreading.rb