Sha256: 2333e8e0a1bfbd1ecc2e698f164cd1a9b8135ac4d0702a7232627a01afc3b031

Contents?: true

Size: 1.52 KB

Versions: 27

Compression:

Stored size: 1.52 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_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

27 entries across 27 versions & 1 rubygems

Version Path
rbbt-util-5.14.10 test/rbbt/test_packed_index.rb
rbbt-util-5.14.9 test/rbbt/test_packed_index.rb
rbbt-util-5.14.8 test/rbbt/test_packed_index.rb
rbbt-util-5.14.7 test/rbbt/test_packed_index.rb
rbbt-util-5.14.6 test/rbbt/test_packed_index.rb
rbbt-util-5.14.5 test/rbbt/test_packed_index.rb
rbbt-util-5.14.4 test/rbbt/test_packed_index.rb