Sha256: 2f2b441355a1655ed9521bb7c66fe7ad551cd77ebca663090add62af4d722e94

Contents?: true

Size: 1.53 KB

Versions: 707

Compression:

Stored size: 1.53 KB

Contents

require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'test_helper.rb')
require 'rbbt/packed_index'

class TestPackedIndex < Test::Unit::TestCase
  def _test_packed_index

    TmpFile.with_file do |tmpfile|
      pi = PackedIndex.new tmpfile, true, %w(i i 23s f f f f f)
      100.times do |i|
        pi << [i, i+2, i.to_s * 10, rand, rand, rand, rand, rand]
      end
      pi << nil
      pi << nil
      pi.close
      pi = PackedIndex.new(tmpfile, false)
      Misc.benchmark(1000) do
      100.times do |i|
        assert_equal i, pi[i][0] 
        assert_equal i+2, pi[i][1] 
      end
      end
      assert_equal nil, pi[100]
      assert_equal nil, pi[101]
    end
  end

  def test_bgzip

    size = 1000000
    density = 0.1

    access = []
    (size * density).to_i.times do
      access << rand(size-1) + 1
    end
    access.sort!
    access.uniq!

    TmpFile.with_file do |tmpfile|
      pi = PackedIndex.new tmpfile, true, %w(i i 23s f f f f f)
      size.times do |i|
        pi << [i, i+2, i.to_s * 10, rand, rand, rand, rand, rand]
      end
      pi << nil
      pi << nil
      pi.close

      pi = PackedIndex.new(tmpfile, false)
      Misc.benchmark do
        access.each do |point|
          assert_equal point+2, pi[point][1]
        end
      end

      `bgzip #{tmpfile} `
      `mv #{tmpfile}.gz #{tmpfile}.bgz`

      pi = PackedIndex.new(tmpfile + '.bgz', false)
      pi[0]
      Misc.benchmark do
        access.each do |point|
          assert_equal point+2, pi[point][1]
        end
      end
    end
  end
end

Version data entries

707 entries across 707 versions & 1 rubygems

Version Path
rbbt-util-5.42.0 test/rbbt/test_packed_index.rb
rbbt-util-5.41.1 test/rbbt/test_packed_index.rb
rbbt-util-5.41.0 test/rbbt/test_packed_index.rb
rbbt-util-5.40.5 test/rbbt/test_packed_index.rb
rbbt-util-5.40.4 test/rbbt/test_packed_index.rb
rbbt-util-5.40.3 test/rbbt/test_packed_index.rb
rbbt-util-5.40.0 test/rbbt/test_packed_index.rb
rbbt-util-5.39.0 test/rbbt/test_packed_index.rb
rbbt-util-5.38.1 test/rbbt/test_packed_index.rb
rbbt-util-5.38.0 test/rbbt/test_packed_index.rb
rbbt-util-5.37.16 test/rbbt/test_packed_index.rb
rbbt-util-5.37.15 test/rbbt/test_packed_index.rb
rbbt-util-5.37.14 test/rbbt/test_packed_index.rb
rbbt-util-5.37.13 test/rbbt/test_packed_index.rb
rbbt-util-5.37.12 test/rbbt/test_packed_index.rb
rbbt-util-5.37.11 test/rbbt/test_packed_index.rb
rbbt-util-5.37.10 test/rbbt/test_packed_index.rb
rbbt-util-5.37.9 test/rbbt/test_packed_index.rb
rbbt-util-5.37.8 test/rbbt/test_packed_index.rb
rbbt-util-5.37.6 test/rbbt/test_packed_index.rb