Closed LebronKodan closed 2 years ago
You'd have to ask this over in https://github.com/smartystreets/assertions, as that's the assertions library that convey uses.
However, I think the simpler approach might be to:
1) Use a map[int]struct{}
to store sets of integers. Maps are not order-preserving, and so ShouldResemble will show them as equal. Plus, set-membership operations (like union, or "contains") will be faster :).
2) If you really want them to be unordered slices, just wrap them using the stdlib sort.IntSlice type: sort.IntSlice(a).Sort()
. After that a
would be sorted (and do the same for b). Then ShouldResemble will be able to compare them as equal.
The core implementation of ElementsMatch looks like it could be a fairly expensive O(NM), so it wouldn't be a good idea for large lists. If I understand what they're doing there, I think there's actually an O(max(N,M)log N) implementation though.
In some scenarios, we need a function like ShouldElementsMatch to compare two slices without order, e.g.
testify has ElementsMatch, does goconvey provide something like this?