File: metaphone_test.rb

package info (click to toggle)
ruby-text 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 564 kB
  • sloc: ruby: 1,147; makefile: 4
file content (40 lines) | stat: -rw-r--r-- 1,360 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require_relative "./test_helper"
require "text/metaphone"
require 'yaml'

class MetaphoneTest < Test::Unit::TestCase

  def test_cases
    YAML.load(data_file('metaphone.yml')).each do |input, expected_output|
      assert_equal expected_output, Text::Metaphone.metaphone(input)
    end
  end

  def test_cases_for_buggy_implementation
    YAML.load(data_file('metaphone_buggy.yml')).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