summaryrefslogtreecommitdiff
path: root/test/did_you_mean/tree_spell/test_change_word.rb
blob: 613e11b869b9703544fab829fb9071ef6c392f0b (plain)
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
require_relative '../helper'
require_relative 'change_word'

class ChangeWordTest < Test::Unit::TestCase
  def setup
    @input = 'spec/services/anything_spec'
    @cw = TreeSpell::ChangeWord.new(@input)
    @len = @input.length
  end

  def test_deleletion
    assert_match @cw.deletion(5), 'spec/ervices/anything_spec'
    assert_match @cw.deletion(@len - 1), 'spec/services/anything_spe'
    assert_match @cw.deletion(0), 'pec/services/anything_spec'
  end

  def test_substitution
    assert_match @cw.substitution(5, '$'), 'spec/$ervices/anything_spec'
    assert_match @cw.substitution(@len - 1, '$'), 'spec/services/anything_spe$'
    assert_match @cw.substitution(0, '$'), '$pec/services/anything_spec'
  end

  def test_insertion
    assert_match @cw.insertion(7, 'X'), 'spec/serXvices/anything_spec'
    assert_match @cw.insertion(0, 'X'), 'Xspec/services/anything_spec'
    assert_match @cw.insertion(@len - 1, 'X'), 'spec/services/anything_specX'
  end

  def test_transposition
    n = @input.length
    assert_match @cw.transposition(0, -1), 'psec/services/anything_spec'
    assert_match @cw.transposition(n - 1, +1), 'spec/services/anything_spce'
    assert_match @cw.transposition(4, +1), 'specs/ervices/anything_spec'
    assert_match @cw.transposition(4, -1), 'spe/cservices/anything_spec'
    assert_match @cw.transposition(21, -1), 'spec/services/anythign_spec'
    assert_match @cw.transposition(21, +1), 'spec/services/anythin_gspec'
  end
end