51#if GTEST_HAS_GLOBAL_STRING
55 *
this =
Eq(
static_cast<std::string
>(
s));
62 *
this =
Eq(std::string(
s));
69#if GTEST_HAS_GLOBAL_STRING
73 *
this =
Eq(
static_cast<std::string
>(
s));
81#if GTEST_HAS_GLOBAL_STRING
85 *
this =
Eq(
static_cast<::
string>(
s));
98 *
this =
Eq(
static_cast<::
string>(
s));
115#if GTEST_HAS_GLOBAL_STRING
124 *
this =
Eq(std::string(
s));
130 *
this =
Eq(std::string(
s));
137#if GTEST_HAS_GLOBAL_STRING
146 *
this =
Eq(std::string(
s));
152 *
this =
Eq(std::string(
s));
164 const char* matcher_name,
167 if (param_values.size() >= 1) result +=
" " +
JoinAsTuple(param_values);
168 return negation ?
"not (" + result +
")" : result;
237 left_(graph_->LhsSize(), kUnused),
238 right_(graph_->RhsSize(), kUnused) {}
243 ::std::vector<char> seen;
256 for (
size_t ilhs = 0; ilhs < graph_->
LhsSize(); ++ilhs) {
260 <<
"ilhs: " << ilhs <<
", left_[ilhs]: " << left_[ilhs];
262 seen.assign(graph_->
RhsSize(), 0);
263 TryAugment(ilhs, &seen);
266 for (
size_t ilhs = 0; ilhs < left_.size(); ++ilhs) {
267 size_t irhs = left_[ilhs];
268 if (irhs == kUnused)
continue;
275 static const size_t kUnused =
static_cast<size_t>(-1);
293 bool TryAugment(
size_t ilhs, ::std::vector<char>* seen) {
294 for (
size_t irhs = 0; irhs < graph_->
RhsSize(); ++irhs) {
295 if ((*seen)[irhs])
continue;
296 if (!graph_->
HasEdge(ilhs, irhs))
continue;
309 if (right_[irhs] == kUnused || TryAugment(right_[irhs], seen)) {
319 const MatchMatrix* graph_;
331 ::std::vector<size_t> left_;
332 ::std::vector<size_t> right_;
337const size_t MaxBipartiteMatchState::kUnused;
344 ::std::ostream* stream) {
345 typedef ElementMatcherPairs::const_iterator Iter;
346 ::std::ostream&
os = *stream;
348 const char* sep =
"";
349 for (Iter it = pairs.begin(); it != pairs.end(); ++it) {
351 <<
"element #" << it->first <<
", "
352 <<
"matcher #" << it->second <<
")";
359 for (
size_t ilhs = 0; ilhs <
LhsSize(); ++ilhs) {
360 for (
size_t irhs = 0; irhs <
RhsSize(); ++irhs) {
361 char& b = matched_[SpaceIndex(ilhs, irhs)];
373 for (
size_t ilhs = 0; ilhs <
LhsSize(); ++ilhs) {
374 for (
size_t irhs = 0; irhs <
RhsSize(); ++irhs) {
375 char& b = matched_[SpaceIndex(ilhs, irhs)];
376 b =
static_cast<char>(rand() & 1);
382 ::std::stringstream ss;
383 const char* sep =
"";
384 for (
size_t i = 0; i <
LhsSize(); ++i) {
395 ::std::ostream*
os)
const {
398 if (matcher_describers_.empty()) {
402 if (matcher_describers_.size() == 1) {
403 *
os <<
"has " <<
Elements(1) <<
" and that element ";
404 matcher_describers_[0]->DescribeTo(
os);
407 *
os <<
"has " <<
Elements(matcher_describers_.size())
408 <<
" and there exists some permutation of elements such that:\n";
411 *
os <<
"a surjection from elements to requirements exists such that:\n";
414 *
os <<
"an injection from elements to requirements exists such that:\n";
418 const char* sep =
"";
419 for (
size_t i = 0; i != matcher_describers_.size(); ++i) {
422 *
os <<
" - element #" << i <<
" ";
424 *
os <<
" - an element ";
426 matcher_describers_[i]->DescribeTo(
os);
436 ::std::ostream*
os)
const {
439 if (matcher_describers_.empty()) {
440 *
os <<
"isn't empty";
443 if (matcher_describers_.size() == 1) {
446 matcher_describers_[0]->DescribeNegationTo(
os);
449 *
os <<
"doesn't have " <<
Elements(matcher_describers_.size())
450 <<
", or there exists no permutation of elements such that:\n";
453 *
os <<
"no surjection from elements to requirements exists such that:\n";
456 *
os <<
"no injection from elements to requirements exists such that:\n";
459 const char* sep =
"";
460 for (
size_t i = 0; i != matcher_describers_.size(); ++i) {
463 *
os <<
" - element #" << i <<
" ";
465 *
os <<
" - an element ";
467 matcher_describers_[i]->DescribeTo(
os);
482 const ::std::vector<std::string>& element_printouts,
485 ::std::vector<char> element_matched(matrix.
LhsSize(), 0);
486 ::std::vector<char> matcher_matched(matrix.
RhsSize(), 0);
488 for (
size_t ilhs = 0; ilhs < matrix.
LhsSize(); ilhs++) {
489 for (
size_t irhs = 0; irhs < matrix.
RhsSize(); irhs++) {
490 char matched = matrix.
HasEdge(ilhs, irhs);
491 element_matched[ilhs] |= matched;
492 matcher_matched[irhs] |= matched;
498 "where the following matchers don't match any elements:\n";
499 for (
size_t mi = 0; mi < matcher_matched.size(); ++mi) {
500 if (matcher_matched[mi])
continue;
503 *listener << sep <<
"matcher #" << mi <<
": ";
504 matcher_describers_[mi]->DescribeTo(listener->
stream());
512 "where the following elements don't match any matchers:\n";
513 const char* outer_sep =
"";
515 outer_sep =
"\nand ";
517 for (
size_t ei = 0; ei < element_matched.size(); ++ei) {
518 if (element_matched[ei])
continue;
521 *listener << outer_sep << sep <<
"element #" << ei <<
": "
522 << element_printouts[ei];
535 size_t max_flow = matches.size();
539 *listener <<
"where no permutation of the elements can satisfy all "
540 "matchers, and the closest match is "
541 << max_flow <<
" of " << matrix.
RhsSize()
542 <<
" matchers with the pairings:\n";
543 LogElementMatcherPairVec(matches, listener->
stream());
551 <<
"where not all elements can be matched, and the closest match is "
552 << max_flow <<
" of " << matrix.
RhsSize()
553 <<
" matchers with the pairings:\n";
554 LogElementMatcherPairVec(matches, listener->
stream());
559 if (matches.size() > 1) {
561 const char* sep =
"where:\n";
562 for (
size_t mi = 0; mi < matches.size(); ++mi) {
563 *listener << sep <<
" - element #" << matches[mi].first
564 <<
" is matched by matcher #" << matches[mi].second;
::std::ostream * stream()
bool IsInterested() const
std::string DebugString() const
bool HasEdge(size_t ilhs, size_t irhs) const
MaxBipartiteMatchState(const MatchMatrix &graph)
ElementMatcherPairs Compute()
void DescribeToImpl(::std::ostream *os) const
bool FindPairing(const MatchMatrix &matrix, MatchResultListener *listener) const
bool VerifyMatchMatrix(const ::std::vector< std::string > &element_printouts, const MatchMatrix &matrix, MatchResultListener *listener) const
void DescribeNegationToImpl(::std::ostream *os) const
static Message Elements(size_t n)
UnorderedMatcherRequire::Flags match_flags() const
#define GTEST_CHECK_(condition)
#define GTEST_DISALLOW_ASSIGN_(type)
::std::vector< ElementMatcherPair > ElementMatcherPairs
GTEST_API_ std::string ConvertIdentifierNameToWords(const char *id_name)
::std::pair< size_t, size_t > ElementMatcherPair
GTEST_API_ std::string JoinAsTuple(const Strings &fields)
::std::vector< ::std::string > Strings
GTEST_API_ std::string FormatMatcherDescription(bool negation, const char *matcher_name, const Strings ¶m_values)
GTEST_API_ ElementMatcherPairs FindMaxBipartiteMatching(const MatchMatrix &g)
internal::Eq2Matcher Eq()