Sha256: 71549a37a30e78c4ee6d04671c0b0fe918e0753002dda89559fd588c5133bb47

Contents?: true

Size: 643 Bytes

Versions: 5

Compression:

Stored size: 643 Bytes

Contents

require 'spec_helper'

describe ::SlideRule::DistanceCalculators::Levenshtein do
  let(:subject) { described_class.new }

  it 'should calculate perfect match' do
    expect(subject.calculate('this is a test', 'this is a test')).to eq(0.0)
  end

  it 'should calculate distance as distance divided by length of longest string' do
    expect(subject.calculate('this is a test', 'this is a test!').round(4)).to eq((1.0 / 15).round(4))
  end

  it 'should handle nils' do
    expect(subject.calculate(nil, nil)).to eq(0.0)
    expect(subject.calculate(nil, 'goodbye')).to eq(1.0)
    expect(subject.calculate('hello', nil)).to eq(1.0)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
slide_rule-1.0.1 spec/slide_rule/distance_calculators/levenshtein_spec.rb
slide_rule-1.0.0 spec/slide_rule/distance_calculators/levenshtein_spec.rb
slide_rule-0.2.2 spec/slide_rule/distance_calculators/levenshtein_spec.rb
slide_rule-0.2.1 spec/slide_rule/distance_calculators/levenshtein_spec.rb
slide_rule-0.1.2 spec/slide_rule/distance_calculators/levenshtein_spec.rb