Writing tests: assertion on data graphs with lists


maybe someone can help me with this?

specific problem
I have a result on the left which is a struct/map with a nested list:
left = %{id: 1, things: [1,2,3,4,5]}

And I have an expected on the right
right = %{id: 1, things: [2,1,3,4,5]}

assert left === right will fail, because the ordering within the list is not the same. But I don’t care about ordering. What I’m interested in, is that each item within that list is present.
Within my implementation code, I don’t want to order the list, because sorting the list isn’t important for my domain (not a domain concept).

Is there a way to achieve this? Consider that my graph is bigger than in this example :slight_smile:

Coming from c#, I organized my code pushing IO to the edges (hexagonal) so that a have a pure domain model. Then I write feature-tests (integrating business classes) without IO to see, if the feature is working. UnitTests are also there, but poor.

Would that make sense in FP? Do you write UnitTests (tests for each function)? Do you write Feature-Tests without Unit-Tests? Both?

Thanks, Marcello

Split up the assertions.

Match on the shape of the map, and check individual values for “equality”. Transform the list into a MapSet first.


omg - yeah - of course! :weary:
thank you!