Sha256: 2e8214b7898a9bd6a2cf61a95b0b95c8c0599969ce1c5d1c2376f90fb346d61f

Contents?: true

Size: 1.84 KB

Versions: 85

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Hashdiff do
  it 'is able to find LCS between two equal array' do
    a = [1, 2, 3]
    b = [1, 2, 3]

    lcs = described_class.lcs(a, b)
    lcs.should == [[0, 0], [1, 1], [2, 2]]
  end

  it 'is able to find LCS between two close arrays' do
    a = [1.05, 2, 3.25]
    b = [1.06, 2, 3.24]

    lcs = described_class.lcs(a, b, numeric_tolerance: 0.1)
    lcs.should == [[0, 0], [1, 1], [2, 2]]
  end

  it 'strips strings when finding LCS if requested' do
    a = %w[foo bar baz]
    b = [' foo', 'bar', 'zab']

    lcs = described_class.lcs(a, b, strip: true)
    lcs.should == [[0, 0], [1, 1]]
  end

  it 'is able to find LCS with one common elements' do
    a = [1, 2, 3]
    b = [1, 8, 7]

    lcs = described_class.lcs(a, b)
    lcs.should == [[0, 0]]
  end

  it 'is able to find LCS with two common elements' do
    a = [1, 3, 5, 7]
    b = [2, 3, 7, 5]

    lcs = described_class.lcs(a, b)
    lcs.should == [[1, 1], [2, 3]]
  end

  it 'is able to find LCS with two close elements' do
    a = [1, 3.05, 5, 7]
    b = [2, 3.06, 7, 5]

    lcs = described_class.lcs(a, b, numeric_tolerance: 0.1)
    lcs.should == [[1, 1], [2, 3]]
  end

  it 'is able to find LCS with two common elements in different ordering' do
    a = [1, 3, 4, 7]
    b = [2, 3, 7, 5]

    lcs = described_class.lcs(a, b)
    lcs.should == [[1, 1], [3, 2]]
  end

  it 'is able to find LCS with a similarity value' do
    a = [
      { 'value' => 'New', 'onclick' => 'CreateNewDoc()' },
      { 'value' => 'Close', 'onclick' => 'CloseDoc()' }
    ]
    b = [
      { 'value' => 'New1', 'onclick' => 'CreateNewDoc()' },
      { 'value' => 'Open', 'onclick' => 'OpenDoc()' },
      { 'value' => 'Close', 'onclick' => 'CloseDoc()' }
    ]

    lcs = described_class.lcs(a, b, similarity: 0.5)
    lcs.should == [[0, 0], [1, 2]]
  end
end

Version data entries

85 entries across 83 versions & 8 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/hashdiff-1.1.0/spec/hashdiff/lcs_spec.rb
cloudsmith-api-2.0.13 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.1.0/spec/hashdiff/lcs_spec.rb
cloudsmith-api-2.0.12 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.1.0/spec/hashdiff/lcs_spec.rb
cloudsmith-api-2.0.11 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.1.0/spec/hashdiff/lcs_spec.rb
cloudsmith-api-2.0.10 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.1.0/spec/hashdiff/lcs_spec.rb
cloudsmith-api-2.0.9 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.1.0/spec/hashdiff/lcs_spec.rb
cloudsmith-api-2.0.8 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.1.0/spec/hashdiff/lcs_spec.rb
hashdiff-1.1.0 spec/hashdiff/lcs_spec.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/hashdiff-1.0.1/spec/hashdiff/lcs_spec.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/hashdiff-1.0.1/spec/hashdiff/lcs_spec.rb
cloudsmith-api-2.0.7 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/lcs_spec.rb
cloudsmith-api-2.0.6 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/lcs_spec.rb
cloudsmith-api-2.0.5 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/lcs_spec.rb
cloudsmith-api-2.0.4 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/lcs_spec.rb
cloudsmith-api-2.0.3 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/lcs_spec.rb
cloudsmith-api-2.0.2 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/lcs_spec.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/hashdiff-1.0.1/spec/hashdiff/lcs_spec.rb
cloudsmith-api-2.0.1 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/lcs_spec.rb
cloudsmith-api-2.0.0 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/lcs_spec.rb
cloudsmith-api-1.142.3 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/lcs_spec.rb