#How can I assert that two BinaryHeaps are equals ?
1 messages · Page 1 of 1 (latest)
I think there's a subtle difference between two heaps being equal (i.e. having the same structure) and two heaps containing the same elements
I'd expect equality to be the first, but you probably want the second.. I'm guessing Eq isn't implemented to avoid this.
Ok thank you @spare matrix
Im also not sure if there's a good way to implement Eq other than emptying and refilling the heap
In this case, what is the best way to check that two heaps contains the same elements ?
Comparing iterators onto the values ?
the cheap iterators are in "random" order
converting them into a sorted vec and comparing those is the easiest
like this ?
assert_eq!(first_heap.into_sorted_vec(),second_heap.into_sorted_vec());
converting those vecs back into heaps is O(n log(n)) though, just do you're aware
yes, but this consumes your heaps
ok thank you. In my case it's ok to consume the heap (last assertion in my test)