This repository was archived by the owner on Jun 3, 2025. It is now read-only.
power assert and collection asserts #74
christophsturm
started this conversation in
General
Replies: 1 comment
-
One of the ways I have handled this is by pre-calculating the missing and unexpected values in the collection like so: val unknown = actual- expected
val missing = expected- actual.key
assert(unknown.size + missing.size == 0) // Add sizes so both values are diagramed. I think this is another reason to start tackling #45. These sorts of diffs would be a fantastic enhancement for assertion libraries. I've also opened #80 based on your example assertion which includes the vararg array. The array itself is constant so can probably be excluded while still including the values within the array. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I wonder what a good way to do asserts on collections would be in power assert, especially where to show the diffs.
I have this helper
and I use it like this:
assertion errors look like this:
which is easy to read unless the collection gets too long. But for longer collections a diff would be nice.
One quick idea would be to have the containsExactlyInOrder() helper return a list of differences, and write the assert like this:
maybe there could be an assert that asserts on an empty list, for especially this use case. or a sealed class
and a containsExactlyInAnyOrder returns DiffResult and we have an assert that asserts that DiffResult == Same
then i could just write
and still get a diff result. I like this version best, but its also akward to have a
containsExactlyInAnyOrder
function that does not return boolean, so maybe that function would need to have a different name.lastly there is of course the option to do an separate assert for this:
Beta Was this translation helpful? Give feedback.
All reactions