Sha256: ccc2e6b9d292d956a6fd8b7c1990ff021879abf90859aab452276d91df62259b

Contents?: true

Size: 1.1 KB

Versions: 707

Compression:

Stored size: 1.1 KB

Contents

require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
require 'rbbt-util'
require 'rbbt/tsv'
require 'rbbt/tsv/change_id'

class TestTSVChangeID < Test::Unit::TestCase

  FILE1=<<-EOF
#: :sep=' '
#A B C
a b c
aa bb cc
  EOF

  FILE2=<<-EOF
#: :sep=' '
#X Y Z
x y z
xx yy zz
  EOF

  IDENTIFIERS=<<-EOF
#: :sep=' '
#A X
a x
aa xx
  EOF

  def tsv(text, options = {})
    options = Misc.add_defaults options, :type => :list
    TSV.open StringIO.new(text), options
  end

  def setup
    @f1 = tsv(FILE1)
    @f2 = tsv(FILE2)
    @f3 = tsv(FILE2, :key_field => "Y")
    @id = tsv(IDENTIFIERS)
  end

  def test_swap_id
    @f3.identifiers = @id
    assert_equal "a", @f3.swap_id("X","A")["y"]["A"]
  end


  def test_change_key
    @f1.identifiers = @id
    assert @f1.change_key("X").include? "x"
  end

  def test_translate_key
    @f1.identifiers = @id
    assert TSV.translate(@f1, @f1.key_field, "X", :persist => false).include? "x"
  end

  def test_translate_key_persist
    @f1.identifiers = @id
    assert TSV.translate(@f1, @f1.key_field, "X", :persist => true).include? "x"
  end
end

Version data entries

707 entries across 707 versions & 1 rubygems

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