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.32.26 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.25 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.24 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.23 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.22 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.21 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.20 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.18 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.17 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.16 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.15 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.13 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.12 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.11 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.10 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.9 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.7 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.6 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.5 test/rbbt/tsv/test_change_id.rb
rbbt-util-5.32.4 test/rbbt/tsv/test_change_id.rb