Google Mock users,
I noticed that it's a very common pattern that people want to match two containers pointwise using a custom matcher. The Pointwise() matcher was designed for this:
Pointwise(m, expected_container)
returns a matcher that matches a container whose size is the same as expected_container and the inner matcher m matches (the i-th element in the actual container, the i-th element in the expected container) for all i. Here m must be a matcher for a 2-tuple.
For example, given that Lt() is a matcher that matches a 2-tuple of numbers where the first number is less than the second,
Pointwise(Lt(), upperbounds)
is a matcher that matches a container whose i-th element is less than the i-th element of upperbounds.
However, often the custom matcher one needs falls out of this small set, and the user is expected to define the custom matcher himself.
In a lot of such cases, there is already an existing one-parameter matcher that does what we want, except that we need a no-parameter matcher. For example, in Daniel's case he needs
DoubleTupleEq()
which matches a 2-tuple (x, y) iff the one-parameter matcher DoubleEq(y) matches x.
I think it would be very useful to provide a construct that turns a one-parameter matcher into a no-parameter matcher for 2-tuples, e.g.
TUPLE2_MATCHER(DoubleTupleEq, DoubleEq);
This macro will define a new matcher DoubleTupleEq() from DoubleEq, and it will take care of defining the description of the new matcher in terms of the description of DoubleEq.
Thoughts?
---------- Forwarded message ----------
From:
Zhanyong Wan (λx.x x) <w...@google.com>
Date: Sun, Jul 7, 2013 at 3:52 PM
Subject: Re: [googlemock: 1901] Checking if floating-point arrays are nearly equal
To: "Daniel P. Volpato" <
danielp...@gmail.com>
Cc: Google C++ Mocking Framework <
googl...@googlegroups.com>
--
Zhanyong