The following isn't tied to any specific language or framework, but am curious what others may be doing.
Recently, I've come across more situations where my implementation of Equatable ultimately needs to be split. For example, in unit testing, you want to make sure == operates on all properties in a struct or class (so that XCTAssertEqual can be used). But in production code, you may want == to only take certain properties into account.
I'm thinking of adding another protocol, that when implemented, will provide an operator (e.g. ~=) to signify "equivalence" (i.e. zero or more properties may be ignored). Then, add another assertion function that ultimately calls that operator given two items of a given type that conform to that protocol.
Ultimately, this would provide the following system:
=== for identity
== for Equatable
~= for equivalence
Thoughts?
One area that gets a bit tricky will be when working with sets. e.g. if I wish to maintain a set of items such that I don't want two or more equivalent items in the set, I'd need to do check each item in the set before inserting a new one (by using ~=).