Sha256: 2a71e9b3dc36aa7c2074ca92353e00d693a3d1ccdbb6f62dff99c243e41b4b51

Contents?: true

Size: 1011 Bytes

Versions: 2

Compression:

Stored size: 1011 Bytes

Contents

require 'ting'
require 'test/unit'
require 'csv'


# This test uses the chart from piyin.info to compare all implemted conversion types
# Since I can't find another reference of the hanyu pinyin 'lo', I have removed it from the table

class TestCompare < Test::Unit::TestCase
  CHART=CSV.parse(IO.read(File.dirname(__FILE__)+'/../lib/ting/data/comparison.csv'))
  COMPARE=[:hanyu, :wadegiles, :zhuyin, :tongyong]


  # Test all combinations, included parsing/unparsing the same type

  def test_do_comparisons
    COMPARE.each do |from|
      COMPARE.each do |to|
        compare(from,to)
      end
    end
  end

  def compare(from, to)
    reader = Ting.reader(from, :no_tones)
    writer = Ting.writer(to, :no_tones)

    ifrom = CHART[0].index from.to_s
    ito   = CHART[0].index to.to_s

    CHART[1..-1].each do |vals|
      assert_equal(vals[ito].strip, writer << (reader << vals[ifrom].strip), "Converting from #{from} to #{to} value #{vals[ito]}")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ting-0.2.1 test/test_comparison.rb
ting-0.2.0 test/test_comparison.rb