Sha256: fb9374bdcca1dd38f5a851365ae9221f0b8fcb6b1175f070de5fa3399f2cf639

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 KB

Contents

require 'spec_helper'

describe HashDiff do
  it 'is able to diff two equal array' do
    a = [1, 2, 3]
    b = [1, 2, 3]

    diff = described_class.diff_array_lcs(a, b)
    diff.should == []
  end

  it 'is able to diff two arrays with one element in common' do
    a = [1, 2, 3]
    b = [1, 8, 7]

    diff = described_class.diff_array_lcs(a, b)
    diff.should == [['-', 2, 3], ['-', 1, 2], ['+', 1, 8], ['+', 2, 7]]
  end

  it 'is able to diff two arrays with nothing in common' do
    a = [1, 2]
    b = []

    diff = described_class.diff_array_lcs(a, b)
    diff.should == [['-', 1, 2], ['-', 0, 1]]
  end

  it 'is able to diff an empty array with an non-empty array' do
    a = []
    b = [1, 2]

    diff = described_class.diff_array_lcs(a, b)
    diff.should == [['+', 0, 1], ['+', 1, 2]]
  end

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

    diff = described_class.diff_array_lcs(a, b)
    diff.should == [['-', 0, 1], ['+', 0, 2], ['+', 2, 7], ['-', 4, 7]]
  end

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

    diff = described_class.diff_array_lcs(a, b)
    diff.should == [['-', 0, 1], ['+', 0, 2], ['-', 2, 4], ['+', 3, 5]]
  end

  it 'is able to diff two arrays with similar elements' do
    a = [{ 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5 }, 3]
    b = [1, { 'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5 }]
    diff = described_class.diff_array_lcs(a, b)
    diff.should == [['+', 0, 1], ['-', 2, 3]]
  end
end

Version data entries

6 entries across 4 versions & 2 rubygems

Version Path
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.8/spec/hash_diff/diff_array_spec.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/hashdiff-0.3.8/spec/hash_diff/diff_array_spec.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.8/spec/hash_diff/diff_array_spec.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/hashdiff-0.3.8/spec/hash_diff/diff_array_spec.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/hashdiff-0.3.8/spec/hash_diff/diff_array_spec.rb
hashdiff-0.3.8 spec/hash_diff/diff_array_spec.rb