Pursuing SO question AssertJ multidimensional arrays assertion (deep equals)
i'd like to try to make an assertion for multidimensional arrays.
I think i'd implement it similar to native Java Arrays#deepEquals(), just "extending" it with nicer assertion exceptions, including indexes and actual/expected values.
int[][] expected = {
new int[]{1, 0, 1},
new int[]{0, 0, 0},
new int[]{1, 1, 1}
};
int[][] actual = gameOfLife.play(board);
assertThat(actual).isDeepEqualTo(expected);
That would be a nice addition, bear in mind that it would need to be added for all primitive types and Object which is some substantial work.
Two years and nothing happened to this issue, so I took it and results can be seen in this quite a big pull request.
@mwajcht let's start with one of the array type (int for example) and then when this is done, we can replicate it to other types
Ok, I created the second, much smaller pull request. It contains only changes for int two-dimensional arrays. It should be easier to make the code review.
thanks, that will make it much easier!
@joel-costigliola As assertions for two-dimensional int arrays are already merged, I can apply your comments to other types. Do you prefer separate pull requests for each type or all-in-one?
@mwajcht I would prefer separate PRs, I might have missed things to improve (hopefully mot many) and seeing more than 100 files ina PR just sucks the energy out of me ;-)
I added a few pull requests with assertions for other types.
@mwajcht waht would you think of renaming hasSize to hasDimensions, the latter feels more natural and shows we are checking for multiple dimensions whereas the singular size?
BTW, I have renamed the master branch to main, your PR have been updated accordingly in this repo but not yours, don't be surprised.
@joel-costigliola Your suggestion regarding change hasSize->hasDimensions sounds reasonable. I created a new pull request which changes the existing methods (for int[][] and char[][]) to avoid changing them in each of the remaining pull requests. Once it's merged, I will update the rest of pull requests.
awesome thank you so much @mwajcht
@mwajcht for consistency, we now need to change is hasSameSizeAs to hasSameDimensionsAs, I can take care of it if you are busy.
@joel-costigliola Ok, please change hasSameSizeAs to hasSameDimensionsAs. Once it's done, I will rebase and change the rest of waiting pull requests.
@mwajcht I renamed hasSameSizeAs to hasSameDimensionsAs and made quite a lot of changes too:
isEmpty andisNotEmpty that should check there elements absence/presence, ex{{}, {}} is empty as it does no have any elements.I updated the pull requests for long[][], short[][] and byte[][] to contain all the changes introduced above. In the upcoming days I will also update other pull requests.
Now all pull requests should be up-to-date.
Finally done, thanks for such huge and good work @mwajcht!