Writing custom Hamcrest matchers
The previous section ended with the Equals
matcher specialized to call compareEq
for floating-point types. We also modified the tests for large floating-point values because they could use the Hamcrest style and the Equals
matcher.
We left the tests for small floating-point values unchanged because those tests need to make sure that the actual and expected values are not equal.
We want to update the small floating-point value tests and need a way to test for not equal values. Maybe we could create a new matcher called NotEquals
, or we could put the not
keyword in front of the Equals
matcher.
I’d like to avoid the need for a new matcher if possible. We don’t really need any new behavior—we just need to flip the results of the existing Equals
matcher. Let’s try modifying the small floating-point value tests to look like this in Hamcrest.cpp
:
TEST("Test small float values")
{
//...