Sha256: 24db8b781007312809c32ca4f93b2ac9b37f6d7895ebeb554647e7697e033a08

Contents?: true

Size: 1.57 KB

Versions: 86

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

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

86 entries across 84 versions & 9 rubygems

Version Path
cloudsmith-api-1.142.3 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
cloudsmith-api-1.120.3 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
cloudsmith-api-1.61.3 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
cloudsmith-api-1.42.3 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
cloudsmith-api-1.33.7 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
cloudsmith-api-1.30.0 vendor/bundle/ruby/2.6.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/hashdiff-1.0.1/spec/hashdiff/diff_array_spec.rb