Sha256: b0aebe8ff7ddac8efc75538b4836ed5c0b173d9b1ff805f52aacd248cc90cda3

Contents?: true

Size: 1.39 KB

Versions: 658

Compression:

Stored size: 1.39 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
require 'rbbt/tsv'
require 'rbbt/tsv/util'
require 'rbbt/util/tmpfile'
require 'test/unit'

class TestTSVUtil < Test::Unit::TestCase

  def test_field_counts
   content =<<-EOF
#Id    ValueA    ValueB    OtherID
row1    a|aa|aaa    b    Id1|Id2
row2    A    B    Id3
    EOF

    TmpFile.with_file(content) do |filename|
      tsv = TSV.open(filename, :sep => /\s+/)

      assert_equal 2, TSV.field_match_counts(tsv, ["a","A","a","b","Id3"])["ValueA"]
      assert_equal nil, TSV.field_match_counts(tsv, ["ValueA"])["ValueA"]
    end
  end

  def test_marshal
   content =<<-EOF
#Id    ValueA    ValueB    OtherID
row1    a|aa|aaa    b    Id1|Id2
row2    A    B    Id3
    EOF

    TmpFile.with_file(content) do |filename|
      tsv = TSV.open(filename, :sep => /\s+/)

      assert TSV === Marshal.load(Marshal.dump(tsv))
      assert_equal tsv.to_hash, Marshal.load(Marshal.dump(tsv)).to_hash
      assert_equal({1 => 1}, Marshal.load(Marshal.dump({1 => 1})))
    end
  end

  def test_replicates
   content =<<-EOF
#Id    ValueA    ValueB    OtherID
row1    a|aa|aaa    b|bb|bbb    Id1|Id2|Id3
row2    A    B    Id3
    EOF

    TmpFile.with_file(content) do |filename|
      tsv = TSV.open(filename, :sep => /\s+/)

      assert_equal 4, tsv.unzip_replicates.length
      assert_equal %w(aa bb Id2), tsv.unzip_replicates["row1(1)"]
    end
  end
end

Version data entries

658 entries across 658 versions & 1 rubygems

Version Path
rbbt-util-5.34.11 test/rbbt/tsv/test_util.rb
rbbt-util-5.34.10 test/rbbt/tsv/test_util.rb
rbbt-util-5.34.9 test/rbbt/tsv/test_util.rb
rbbt-util-5.34.8 test/rbbt/tsv/test_util.rb
rbbt-util-5.34.7 test/rbbt/tsv/test_util.rb
rbbt-util-5.34.5 test/rbbt/tsv/test_util.rb
rbbt-util-5.34.4 test/rbbt/tsv/test_util.rb
rbbt-util-5.34.3 test/rbbt/tsv/test_util.rb
rbbt-util-5.34.2 test/rbbt/tsv/test_util.rb
rbbt-util-5.34.1 test/rbbt/tsv/test_util.rb
rbbt-util-5.34.0 test/rbbt/tsv/test_util.rb
rbbt-util-5.33.21 test/rbbt/tsv/test_util.rb
rbbt-util-5.33.20 test/rbbt/tsv/test_util.rb
rbbt-util-5.33.19 test/rbbt/tsv/test_util.rb
rbbt-util-5.33.18 test/rbbt/tsv/test_util.rb
rbbt-util-5.33.17 test/rbbt/tsv/test_util.rb
rbbt-util-5.33.16 test/rbbt/tsv/test_util.rb
rbbt-util-5.33.15 test/rbbt/tsv/test_util.rb
rbbt-util-5.33.14 test/rbbt/tsv/test_util.rb
rbbt-util-5.33.13 test/rbbt/tsv/test_util.rb