Sets version and EUnit

Hello,

I discovered that sets:new() and sets:from_list() support new version, which should be more efficient and tried to use it, but it makes ?assertEqual to fail unless I create the expected set with v2 as well.
Is this behaviour expected?
Does ?assertEqual just compare passed terms?
I can’t find any set comparison function to rewrite the test as ?assertTrue(sets:equal(Expected, Actual)).

Thanks

2 Likes

Hello!

Since the set type is opaque you cannot/should not compare it directly. Instead, you need to first convert it to a type that you can compare, such as a list. So I would do something like this:

SetToList = fun(Set) -> lists:sort(sets:to_list(Set)) end,
?assertTrue(SetToList(Expected) == SetToList(Actual)).
5 Likes