Sha256: f907c4b75288ca06c34a26a0faa89d09f913c23999671ec4ef787c4aabb3a8df

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

require File.join(File.dirname(__FILE__), 'preamble')
require 'yaml'

class MetaphoneTest < Test::Unit::TestCase

  def test_cases
    YAML.load(File.read(File.rel('data', 'metaphone.txt'))).each do |input, expected_output|
      assert_equal expected_output, Text::Metaphone.metaphone(input)
    end
  end
  
  def test_cases_for_buggy_implementation
    YAML.load(File.read(File.rel('data', 'metaphone_buggy.txt'))).each do |input, expected_output|
      assert_equal expected_output, Text::Metaphone.metaphone(input, :buggy=>true)
    end
  end

  def test_junk
    assert_equal Text::Metaphone.metaphone('foobar'),
      Text::Metaphone.metaphone('%^@#$^f%^&o%^o@b#a@#r%^^&')
    assert_equal Text::Metaphone.metaphone('foobar', :buggy=>true),
      Text::Metaphone.metaphone('%^@#$^f%^&o%^o@b#a@#r%^^&', :buggy=>true)
  end

  def test_caps
    assert_equal Text::Metaphone.metaphone('foobar'),
      Text::Metaphone.metaphone('FOOBAR')
    assert_equal Text::Metaphone.metaphone('foobar', :buggy=>true),
      Text::Metaphone.metaphone('FOOBAR', :buggy=>true)
  end

  def test_string
    assert_equal 'F BR BS', Text::Metaphone.metaphone('foo bar baz')
    assert_equal 'N WT', Text::Metaphone.metaphone('gnu what')
    assert_equal 'F BR BS', Text::Metaphone.metaphone('foo bar baz', :buggy=>true)
    assert_equal 'N WT', Text::Metaphone.metaphone('gnu what', :buggy=>true)
  end

end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
text-0.1.14 test/test_metaphone.rb
text-0.1.13 test/test_metaphone.rb
Text-1.1.2 test/test_metaphone.rb
Text-1.1.0 test/metaphone_test.rb
Text-1.1.1 test/test_metaphone.rb
Text-1.0.0 test/metaphone_test.rb