Sha256: d51a72fa2c989254f0225ff9fa7a6f90151c6763fe39bf832eaa8dab4ad8391b

Contents?: true

Size: 1.84 KB

Versions: 46

Compression:

Stored size: 1.84 KB

Contents

require 'spec_helper'

describe HashDiff do
  it "should be able to find LCS between two equal array" do
    a = [1, 2, 3]
    b = [1, 2, 3]

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

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

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

  it "should strip strings when finding LCS if requested" do
    a = ['foo', 'bar', 'baz']
    b = [' foo', 'bar', 'zab']

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

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

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

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

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

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

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

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

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

  it "should be 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 = HashDiff.lcs(a, b, :similarity => 0.5)
    lcs.should == [[0, 0], [1, 2]]
  end
end

Version data entries

46 entries across 42 versions & 8 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.4/spec/hashdiff/lcs_spec.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb
vagrant-unbundled-2.2.0.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb
vagrant-unbundled-2.1.4.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb
vagrant-unbundled-2.1.2.0 vendor/bundle/ruby/2.3.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb
cloudsmith-api-0.30.7 vendor/bundle/ruby/2.3.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb
color_me_shop-1.0.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb
vagrant-unbundled-2.1.1.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb
vagrant-unbundled-2.0.4.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb
vagrant-unbundled-2.0.3.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.5/spec/hashdiff/lcs_spec.rb
vagrant-unbundled-2.0.1.0 vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.5/spec/hashdiff/lcs_spec.rb
vagrant-unbundled-2.0.1.0 vendor/bundle/ruby/2.4.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb
cloudsmith-api-0.21.4 vendor/bundle/ruby/2.3.0/gems/hashdiff-0.3.7/spec/hashdiff/lcs_spec.rb