Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected difference between diffs of hashes vs. arrays #43

Open
dweebo opened this issue Jul 30, 2018 · 5 comments
Open

Unexpected difference between diffs of hashes vs. arrays #43

dweebo opened this issue Jul 30, 2018 · 5 comments

Comments

@dweebo
Copy link

dweebo commented Jul 30, 2018

I have inputs

a = [1, 2, 3]
b = [1, 10, 3]

and expect a diff of

[["~", "[1]", 2, 10 ]]

but instead I get

[["-", "[1]", 2], ["+", "[1]", 10]]

I expect that because of how hash comparisons work

a = {a:1, b:2, c:3}
b = {a:1, b:10, c:3}
[["~", "b", 2, 10]]

and

a = [1, {a: 0, b: 1}, 3]
b = [1, {a: 0, b: 2}, 3]
[["~", "[1].b", 1, 2]]

Is it possible to get the results I expect?

@liufengyun
Copy link
Owner

@dweebo
Copy link
Author

dweebo commented Jul 30, 2018

I get the same results using diff_array_lcs

@liufengyun
Copy link
Owner

That probably means there are bugs in the implementation. Unfortunately, I don't have time budge to work on it. If you are interested in digging deeper and make a PR, that is always appreciated.

@krzysiek1507
Copy link
Collaborator

It works with: use_lcs: false

pry(main)> HashDiff.diff [1, 2, 3], [1, 10, 3], use_lcs: false
=> [["~", "[1]", 2, 10]]

@krzysiek1507
Copy link
Collaborator

I think LCS doesn't really work here.

obj1 = [1, 1, 1, 2]
obj2 = [2, 1, 1, 1]

HashDiff.diff(obj1, obj2, { use_lcs: true })
=> [["+", "[0]", 2], ["-", "[4]", 2]]

HashDiff.diff(obj1, obj2, { use_lcs: false })
=> [["~", "[0]", 1, 2], ["~", "[3]", 2, 1]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants