Sha256: 41e9308e3010534a54dfefe3feae4cb9a05522279f835c547607e89b95c6d268

Contents?: true

Size: 1.88 KB

Versions: 3

Compression:

Stored size: 1.88 KB

Contents

require 'minitest/autorun'
require 'ununiga/jaso_splitter'

class JamoSplitterTest < Minitest::Test
  def test_extract_chosung
    testgroup = { '가' => 'ㄱ',
                  '낳' => 'ㄴ',
                  '짷' => 'ㅉ',
                  '하' => 'ㅎ'
                }
    testgroup.each do |char, chosung|
      splitter = Ununiga::JasoSplitter.new(char)
      assert_equal chosung, splitter.extract_chosung
    end
  end

  def test_extract_jungsung
    testgroup = { '가' => 'ㅏ',
                  '내' => 'ㅐ',
                  '찋' => 'ㅢ',
                  '휷' => 'ㅠ',
                  '쿄' => 'ㅛ',
                  '왜' => 'ㅙ'
                }
    testgroup.each do |char, jungsung|
      splitter = Ununiga::JasoSplitter.new(char)
      assert_equal jungsung, splitter.extract_jungsung
    end
  end

  def test_extract_jongsung
    testgroup = { '가' => nil,
                  '내' => nil,
                  '찋' => 'ㅎ',
                  '휷' => 'ㄳ'
                }
    testgroup.each do |char, jongsung|
      splitter = Ununiga::JasoSplitter.new(char)
      if jongsung
        assert_equal jongsung, splitter.extract_jongsung
      else
        assert_nil splitter.extract_jongsung
      end
    end
  end

  def test_split
    testgroup = { '신' => ['ㅅ', 'ㅣ', 'ㄴ'],
                  '재' => ['ㅈ', 'ㅐ', nil],
                  '현' => ['ㅎ', 'ㅕ', 'ㄴ'],
                  '꾢' => ['ㄲ', 'ㅛ', 'ㄶ']
                }
    testgroup.each do |char, splitted|
      splitter = Ununiga::JasoSplitter.new(char)
      assert_equal splitted, splitter.split
    end
  end

  def test_non_korean_exception
    %w(a 中 च Қ に).each do |char|
      assert !Ununiga::JasoSplitter.new(char).korean?
    end
  end

  def test_non_single_character_exception
    assert_raises ArgumentError do
      Ununiga::JasoSplitter.new('두글자')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ununiga-1.1.2 test/test_jaso_splitter.rb
ununiga-1.1.1 test/test_jaso_splitter.rb
ununiga-1.1.0 test/test_jaso_splitter.rb