Sha256: db5c67a69c243c2cd4cde928a5462e96e5aade41c8aa4a186b4b6b719bbabc53

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 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 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 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, 0.5)
    lcs.should == [[0, 0], [1, 2]]
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hashdiff-0.1.1 spec/hashdiff/lcs_spec.rb
hashdiff-0.1.0 spec/hashdiff/lcs_spec.rb
hashdiff-0.0.6 spec/hashdiff/lcs_spec.rb
hashdiff-0.0.5 spec/hashdiff/lcs_spec.rb