Sha256: 2c5f3124e2f7f68596099e703992ec0e3d1a281c6d97da343a59cfb447d2eef4
Contents?: true
Size: 775 Bytes
Versions: 4
Compression:
Stored size: 775 Bytes
Contents
require 'diff/lcs' class ArrayHelper # Compare two arrays. def self.compare(expected, actual) sdiff = Diff::LCS.sdiff(expected, actual) changes = {} action_words = { '!' => 'changed', '+' => 'unexpected', '-' => 'missing', '=' => 'unchanged' } sdiff.each_with_index do |change, i| action_word = action_words.fetch(change.action) key = "change_#{i}" attrs = %W/ action=#{action_word} old_pos=#{change.old_position} old_ele=#{change.old_element} new_pos=#{change.old_position} new_ele=#{change.old_element} / value = attrs.join(' ') changes.store(key, value) end {:sdiff => changes} end end
Version data entries
4 entries across 4 versions & 1 rubygems