You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The text was updated successfully, but these errors were encountered:
cpovirk
changed the title
Strange results when comparing List of Arrays
Document when arrays are compared by their contents vs. their object identity
Dec 6, 2021
The main thing to know is that we normally compare objects for equality with Object.equals. And two different arrays with the same contents never compare as equal. By that logic, it's not surprising that a list of arrays will never be equal to another list of arrays (unless both lists contain the same array instances, not just the same contents).
The surprising thing is that, when you use assertThat(foo).isEqualTo(bar), if foo and bar are arrays, then we do compare their contents. That's why the examples in which the array is the "top-level" object work.
We could document this better.
If you do want to compare lists of arrays, then you'll need to tell Truth how to compare the arrays -- probably using Arrays.equals. You can do that by using Fuzzy Truth -- assertThat(listOfArrays).comparingElementsUsing(...).....
(Someone reminded me that the docs for this are better than I'd thought. There's still more we could say, but for some reason, I was thinking that we didn't yet say anything about this.)
Hi, I got some strange results when comparing List of Arrays. It seems to work for Array of Arrays, List of Lists, and Array of Lists though:
This happens in version 1.1.3.
The text was updated successfully, but these errors were encountered: