Sha256: 12bdb25a871ff2bc099542d8804c081e9021925f870d75a35b60ca1314d67efb

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

# coding: utf-8

require 'spec_helper'

RSpec.describe TTY::Shell::Distance, '.distance' do
  let(:object) { described_class.new }

  subject(:distance) { object.distance(*strings) }

  context 'when nil' do
    let(:strings) { [nil, nil] }

    it { is_expected.to eql(0) }
  end

  context 'when empty' do
    let(:strings) { ['', ''] }

    it { is_expected.to eql(0) }
  end

  context 'with one non empty' do
    let(:strings) { ['abc', ''] }

    it { is_expected.to eql(3) }
  end

  context 'when single char' do
    let(:strings) { ['a', 'abc'] }

    it { is_expected.to eql(2) }
  end

  context 'when similar' do
    let(:strings) { ['abc', 'abc'] }

    it { is_expected.to eql(0) }
  end

  context 'when similar' do
    let(:strings) { ['abc', 'acb'] }

    it { is_expected.to eql(1) }
  end

  context 'when end similar' do
    let(:strings) { ['saturday', 'sunday'] }

    it { is_expected.to eql(3) }
  end

  context 'when contain similar' do
    let(:strings) { ['which', 'witch'] }

    it { is_expected.to eql(2) }
  end

  context 'when prefix' do
    let(:strings) { ['sta', 'status'] }

    it { is_expected.to eql(3) }
  end

  context 'when similar' do
    let(:strings) { ['smellyfish','jellyfish'] }

    it { is_expected.to eql(2) }
  end

  context 'when unicode' do
    let(:strings) { ['マラソン五輪代表', 'ララソン五輪代表'] }

    it { is_expected.to eql(1) }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tty-0.2.1 spec/tty/shell/distance/distance_spec.rb
tty-0.2.0 spec/tty/shell/distance/distance_spec.rb
tty-0.1.3 spec/tty/shell/distance/distance_spec.rb