Sha256: 103aa56c188770fa7e4a092260e97ee96baef0b245d4ed1dcb10492d64e3c897

Contents?: true

Size: 1.9 KB

Versions: 15

Compression:

Stored size: 1.9 KB

Contents

require 'test/unit'
require 'amatch'

class TestHamming < Test::Unit::TestCase
  include Amatch

  D = 0.000001

  def setup
    @small   = Hamming.new('test')
    @empty   = Hamming.new('')
    @long    = Hamming.new('A' * 160)
  end

  def test_empty
    assert_in_delta 0, @empty.match(''), D
    assert_in_delta 9, @empty.match('not empty'), D
    assert_in_delta 1, @empty.similar(''), D
    assert_in_delta 0, @empty.similar('not empty'), D
  end

  def test_small_match
    assert_in_delta 4, @small.match(''), D
    assert_in_delta 0, @small.match('test'), D
    assert_in_delta 1, @small.match('testa'), D
    assert_in_delta 5, @small.match('atest'), D
    assert_in_delta 3, @small.match('teast'), D
    assert_in_delta 4, @small.match('est'), D
    assert_in_delta 1, @small.match('tes'), D
    assert_in_delta 3, @small.match('tst'), D
    assert_in_delta 1, @small.match('best'), D
    assert_in_delta 1, @small.match('tost'), D
    assert_in_delta 1, @small.match('tesa'), D
    assert_in_delta 3, @small.match('taex'), D
    assert_in_delta 9, @small.match('aaatestbbb'), D
  end

  def test_small_similar
    assert_in_delta 0.0, @small.similar(''), D
    assert_in_delta 1.0, @small.similar('test'), D
    assert_in_delta 0.8, @small.similar('testa'), D
    assert_in_delta 0.0, @small.similar('atest'), D
    assert_in_delta 0.4, @small.similar('teast'), D
    assert_in_delta 0, @small.similar('est'), D
    assert_in_delta 0.75, @small.similar('tes'), D
    assert_in_delta 0.25, @small.similar('tst'), D
    assert_in_delta 0.75, @small.similar('best'), D
    assert_in_delta 0.75, @small.similar('tost'), D
    assert_in_delta 0.75, @small.similar('tesa'), D
    assert_in_delta 0.25, @small.similar('taex'), D
    assert_in_delta 0.1, @small.similar('aaatestbbb'), D
    assert_in_delta 0.8, @small.pattern.hamming_similar('testa'), D
  end

  def test_long
    assert_in_delta 1.0, @long.similar(@long.pattern), D
  end
end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
amatch-0.4.1 tests/test_hamming.rb
amatch-0.4.0 tests/test_hamming.rb
amatch-0.3.1 tests/test_hamming.rb
patmcnally-amatch-0.2.4 tests/test_hamming.rb
amatch-0.3.0 tests/test_hamming.rb
amatch-rbx-0.2.12 tests/test_hamming.rb
amatch-0.2.11 tests/test_hamming.rb
amatch-0.2.10 tests/test_hamming.rb
amatch-0.2.9 tests/test_hamming.rb
amatch-0.2.8 tests/test_hamming.rb
amatch-0.2.7 tests/test_hamming.rb
amatch-0.2.6 tests/test_hamming.rb
amatch-0.2.5-x86-mswin32 tests/test_hamming.rb
amatch-0.2.5 tests/test_hamming.rb
amatch-0.2.4 tests/test_hamming.rb