36 #include "gmock/gmock-matchers.h"
37 #include "gmock/gmock-generated-matchers.h"
53 const char* matcher_name,
132 ::std::vector<char>
seen;
149 <<
"ilhs: " << ilhs <<
", left_[ilhs]: " <<
left_[ilhs];
155 for (
size_t ilhs = 0; ilhs <
left_.size(); ++ilhs) {
156 size_t irhs =
left_[ilhs];
164 static const size_t kUnused =
static_cast<size_t>(-1);
184 if ((*
seen)[irhs])
continue;
234 typedef ElementMatcherPairs::const_iterator
Iter;
235 ::std::ostream& os = *
stream;
237 const char*
sep =
"";
238 for (
Iter it = pairs.begin();
it != pairs.end(); ++
it) {
240 <<
"element #" <<
it->first <<
", "
241 <<
"matcher #" <<
it->second <<
")";
248 for (
size_t ilhs = 0; ilhs <
LhsSize(); ++ilhs) {
249 for (
size_t irhs = 0; irhs <
RhsSize(); ++irhs) {
262 for (
size_t ilhs = 0; ilhs <
LhsSize(); ++ilhs) {
263 for (
size_t irhs = 0; irhs <
RhsSize(); ++irhs) {
265 b =
static_cast<char>(rand() & 1);
271 ::std::stringstream ss;
272 const char*
sep =
"";
275 for (
size_t j = 0; j <
RhsSize(); ++j) {
284 ::std::ostream* os)
const {
285 switch (match_flags()) {
286 case UnorderedMatcherRequire::ExactMatch:
292 *os <<
"has " <<
Elements(1) <<
" and that element ";
297 <<
" and there exists some permutation of elements such that:\n";
299 case UnorderedMatcherRequire::Superset:
300 *os <<
"a surjection from elements to requirements exists such that:\n";
302 case UnorderedMatcherRequire::Subset:
303 *os <<
"an injection from elements to requirements exists such that:\n";
307 const char*
sep =
"";
310 if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
311 *os <<
" - element #" <<
i <<
" ";
313 *os <<
" - an element ";
316 if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
325 ::std::ostream* os)
const {
326 switch (match_flags()) {
327 case UnorderedMatcherRequire::ExactMatch:
329 *os <<
"isn't empty";
339 <<
", or there exists no permutation of elements such that:\n";
341 case UnorderedMatcherRequire::Superset:
342 *os <<
"no surjection from elements to requirements exists such that:\n";
344 case UnorderedMatcherRequire::Subset:
345 *os <<
"no injection from elements to requirements exists such that:\n";
348 const char*
sep =
"";
351 if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
352 *os <<
" - element #" <<
i <<
" ";
354 *os <<
" - an element ";
357 if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
370 bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix(
371 const ::std::vector<std::string>& element_printouts,
374 ::std::vector<char> element_matched(matrix.
LhsSize(), 0);
375 ::std::vector<char> matcher_matched(matrix.
RhsSize(), 0);
377 for (
size_t ilhs = 0; ilhs < matrix.
LhsSize(); ilhs++) {
378 for (
size_t irhs = 0; irhs < matrix.
RhsSize(); irhs++) {
379 char matched = matrix.
HasEdge(ilhs, irhs);
380 element_matched[ilhs] |= matched;
381 matcher_matched[irhs] |= matched;
385 if (match_flags() & UnorderedMatcherRequire::Superset) {
387 "where the following matchers don't match any elements:\n";
388 for (
size_t mi = 0; mi < matcher_matched.size(); ++mi) {
389 if (matcher_matched[mi])
continue;
392 *listener <<
sep <<
"matcher #" << mi <<
": ";
399 if (match_flags() & UnorderedMatcherRequire::Subset) {
401 "where the following elements don't match any matchers:\n";
402 const char* outer_sep =
"";
404 outer_sep =
"\nand ";
406 for (
size_t ei = 0; ei < element_matched.size(); ++ei) {
407 if (element_matched[ei])
continue;
410 *listener << outer_sep <<
sep <<
"element #" << ei <<
": "
411 << element_printouts[ei];
421 const MatchMatrix& matrix, MatchResultListener* listener)
const {
424 size_t max_flow = matches.size();
425 if ((match_flags() & UnorderedMatcherRequire::Superset) &&
426 max_flow < matrix.RhsSize()) {
427 if (listener->IsInterested()) {
428 *listener <<
"where no permutation of the elements can satisfy all "
429 "matchers, and the closest match is "
430 << max_flow <<
" of " << matrix.RhsSize()
431 <<
" matchers with the pairings:\n";
436 if ((match_flags() & UnorderedMatcherRequire::Subset) &&
437 max_flow < matrix.LhsSize()) {
438 if (listener->IsInterested()) {
440 <<
"where not all elements can be matched, and the closest match is "
441 << max_flow <<
" of " << matrix.RhsSize()
442 <<
" matchers with the pairings:\n";
448 if (matches.size() > 1) {
449 if (listener->IsInterested()) {
450 const char*
sep =
"where:\n";
451 for (
size_t mi = 0; mi < matches.size(); ++mi) {
452 *listener <<
sep <<
" - element #" << matches[mi].first
453 <<
" is matched by matcher #" << matches[mi].second;