-
Notifications
You must be signed in to change notification settings - Fork 210
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
Diff may omit difference of map in struct in slice #329
Comments
I didn't realise until just now but this issue is actually another example of the issue that I opened today - #343 The underlying issue here is not actually map differences in a slice - it's the magnitude of the change. You correctly identify here that the quantity of changed fields directly affects the result, and that's because the diff has tipped over the "half-way" mark (more than half of ANY fields on the object being diffed has changed) and this converts the diff from a "field-wise" diff to a "new object" diff. I'm not sure why this is the case and hopefully we get an answer on #343 |
Much of the reporter is using a complex set of heuristic to determine how to best format the output. Reports like this and #343 are helpful to adjust the heuristic to provide a better human experience. It will unfortunately never be perfect as much of this subjective. |
I traced down heuristic for both this issue and #343 to this code snippet: Changing it to something like: func (r Result) Similar() bool {
// Use NumSame+1 to offset NumSame so that binary comparisons are similar.
return r.NumSame+1 >= r.NumDiff/2
} fixes the issue, but we'll have to think carefully about possible unexpected transitive effects. |
Here's an example of a diff that got worse:
|
Could we pass some kind of option that allows us to manage the evaluation? We can already transform, order, etc via these (very helpful!) functions, could we do something with that? I'm not an expert in the deep internals here but would it potentially be possible to do something with the editscript generation and adding some kind of new Or a more flexible option like I actually don't have a problem at all with the heuristic (it seems like a smart solution to a difficult problem!) - but being able to indicate you want a full property-wise diff would be very valuable in my opinion. |
I wouldn't mind showing the entire object as changed, as long as the entire object is printed, and not just the first couple of fields (which may be identical). Make it a cmpopt, if you'd rather make it opt-in. |
If you look at the implementation, it's a lot of hardcoded constants and heuristics. It is infeasible to expose all of those details through options. It's better to look at case examples of where it operates poorly and tune the heuristics to do better in those cases without undoing how it works on other cases. It takes some finessing, but the reporter gradually do better for more and more situations. Until we've exhausted all the reasonable heuristic tuning, I don't think we should expose any options to alter reporter outputer. |
I've run into a case where the relevant difference is omitted from the cmp.Diff output. I have differences within a large (≥18 entries) map that is nested inside a slice of structs, with some other fields preceding it:
This leads to the following output:
Note how the whole Wrapper is marked as differing, instead of just the map inside, and the interesting differing part of the map is omitted, likely as a direct result.
Reducing the number of differences inside the nested map to 9 yields this much more useful output:
The text was updated successfully, but these errors were encountered: