Better support comparing lists / iterable objects
See original GitHub issueThere is new feature in 3.4.0 version:
assertThat(...).isEqualToComparingFieldByFieldRecursively(...)
but comparing lists is still poor, because we have to use equals(…) method when comparing two objects - it is used by default?
We would like to have methods like:
assertThat(<some iterable>).containsExactlyElementsOf(<some iterable>) - already provided.
assertThat(<some iterable>).containsExactlyElementsOfComparingFieldByField(<some iterable>) - really missing
assertThat(<some iterable>).containsExactlyElementsOfComparingFieldByFieldRecursively(<some iterable>) - missing too
As suggested by @PascalSchumacher we can use:
assertThat((Object) Arrays.asList("a", "c")).isEqualToComparingFieldByFieldRecursively(Arrays.asList("a", "c"));
assertThat((Object) Arrays.asList("a", "c")).isEqualToComparingFieldByField(Arrays.asList("a", "c"));
But this approach works only for identical Lists - internal state of lists such as private fields other than compared objects will be compared too.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Better support comparing lists / iterable objects #46 - GitHub
method when comparing two objects - it is used by default? We would like to have methods like: assertThat(<some iterable>).
Read more >How to Compare Two Lists in Python | DigitalOcean
We can use the Python map() function along with functools.reduce() function to compare the data items of two lists. The map() method accepts...
Read more >Comparing iterables for same content, but not regarding order
Actually, I found this answer, that is just slightly more memory efficient for iterables with duplicates. Nevertheless it should already help ...
Read more >Field Data Types - Iterable Support Center
This article explains different values and data types for fields and events in Iterable and examples of what those types of data would...
Read more >Python List Comparison - Scaler Topics
To compare two lists, we can utilize both approaches simultaneously. The map() method would apply the function to each iterable object, and the ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You a welcome to give it a try. 😃
The feature should added to
AbstractObjectArrayAssert
as well as toAbstractIterableAssert
I think.If you any questions @joel-costigliola and I are there to help. 😃
Just noticed that a field/property by field/property comparison of elements can already be done like this:
so we are just missing a
usingFieldByFieldElementRecursivelyComparator()
method.