37 #include "gmock/gmock-matchers.h" 38 #include "gmock/gmock-generated-matchers.h" 66 #if GTEST_HAS_STRING_PIECE_ 82 *
this =
Eq(s.ToString());
97 *
this =
Eq(s.ToString());
99 #endif // GTEST_HAS_STRING_PIECE_ 106 switch (fields.size()) {
112 string result =
"(" + fields[0];
113 for (
size_t i = 1;
i < fields.size();
i++) {
128 const char* matcher_name,
131 if (param_values.size() >= 1)
133 return negation ?
"not (" + result +
")" : result;
198 class MaxBipartiteMatchState {
209 ::std::vector<char>
seen;
222 for (
size_t ilhs = 0; ilhs <
graph_->LhsSize(); ++ilhs) {
226 <<
"ilhs: " << ilhs <<
", left_[ilhs]: " << left_[ilhs];
228 seen.assign(
graph_->RhsSize(), 0);
229 TryAugment(ilhs, &seen);
232 for (
size_t ilhs = 0; ilhs < left_.size(); ++ilhs) {
233 size_t irhs = left_[ilhs];
241 static const size_t kUnused =
static_cast<size_t>(-1);
260 for (
size_t irhs = 0; irhs <
graph_->RhsSize(); ++irhs) {
263 if (!
graph_->HasEdge(ilhs, irhs))
277 if (right_[irhs] == kUnused || TryAugment(right_[irhs], seen)) {
299 ::std::vector<size_t> left_;
300 ::std::vector<size_t> right_;
314 typedef ElementMatcherPairs::const_iterator
Iter;
315 ::std::ostream& os = *
stream;
317 const char *sep =
"";
318 for (Iter it = pairs.begin(); it != pairs.end(); ++it) {
320 <<
"element #" << it->first <<
", " 321 <<
"matcher #" << it->second <<
")";
332 size_t max_flow = matches.size();
333 bool result = (max_flow == matrix.
RhsSize());
337 *listener <<
"where no permutation of the elements can " 338 "satisfy all matchers, and the closest match is " 339 << max_flow <<
" of " << matrix.
RhsSize()
340 <<
" matchers with the pairings:\n";
346 if (matches.size() > 1) {
348 const char *sep =
"where:\n";
349 for (
size_t mi = 0;
mi < matches.size(); ++
mi) {
350 *listener << sep <<
" - element #" << matches[
mi].first
351 <<
" is matched by matcher #" << matches[
mi].second;
359 bool MatchMatrix::NextGraph() {
360 for (
size_t ilhs = 0; ilhs < LhsSize(); ++ilhs) {
361 for (
size_t irhs = 0; irhs < RhsSize(); ++irhs) {
362 char&
b = matched_[SpaceIndex(ilhs, irhs)];
373 void MatchMatrix::Randomize() {
374 for (
size_t ilhs = 0; ilhs < LhsSize(); ++ilhs) {
375 for (
size_t irhs = 0; irhs < RhsSize(); ++irhs) {
376 char&
b = matched_[SpaceIndex(ilhs, irhs)];
377 b =
static_cast<char>(rand() & 1);
382 string MatchMatrix::DebugString()
const {
383 ::std::stringstream ss;
384 const char *sep =
"";
385 for (
size_t i = 0;
i < LhsSize(); ++
i) {
387 for (
size_t j = 0; j < RhsSize(); ++j) {
395 void UnorderedElementsAreMatcherImplBase::DescribeToImpl(
396 ::std::ostream* os)
const {
397 if (matcher_describers_.empty()) {
401 if (matcher_describers_.size() == 1) {
402 *os <<
"has " << Elements(1) <<
" and that element ";
403 matcher_describers_[0]->DescribeTo(os);
406 *os <<
"has " << Elements(matcher_describers_.size())
407 <<
" and there exists some permutation of elements such that:\n";
408 const char* sep =
"";
409 for (
size_t i = 0;
i != matcher_describers_.size(); ++
i) {
410 *os << sep <<
" - element #" <<
i <<
" ";
411 matcher_describers_[
i]->DescribeTo(os);
416 void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(
417 ::std::ostream* os)
const {
418 if (matcher_describers_.empty()) {
419 *os <<
"isn't empty";
422 if (matcher_describers_.size() == 1) {
423 *os <<
"doesn't have " << Elements(1)
424 <<
", or has " << Elements(1) <<
" that ";
425 matcher_describers_[0]->DescribeNegationTo(os);
428 *os <<
"doesn't have " << Elements(matcher_describers_.size())
429 <<
", or there exists no permutation of elements such that:\n";
430 const char* sep =
"";
431 for (
size_t i = 0;
i != matcher_describers_.size(); ++
i) {
432 *os << sep <<
" - element #" <<
i <<
" ";
433 matcher_describers_[
i]->DescribeTo(os);
443 bool UnorderedElementsAreMatcherImplBase::
444 VerifyAllElementsAndMatchersAreMatched(
445 const ::std::vector<string>& element_printouts,
449 ::std::vector<char> element_matched(matrix.
LhsSize(), 0);
450 ::std::vector<char> matcher_matched(matrix.
RhsSize(), 0);
452 for (
size_t ilhs = 0; ilhs < matrix.
LhsSize(); ilhs++) {
453 for (
size_t irhs = 0; irhs < matrix.
RhsSize(); irhs++) {
454 char matched = matrix.
HasEdge(ilhs, irhs);
455 element_matched[ilhs] |= matched;
456 matcher_matched[irhs] |= matched;
462 "where the following matchers don't match any elements:\n";
463 for (
size_t mi = 0;
mi < matcher_matched.size(); ++
mi) {
464 if (matcher_matched[
mi])
468 *listener << sep <<
"matcher #" << mi <<
": ";
469 matcher_describers_[mi]->DescribeTo(listener->
stream());
477 "where the following elements don't match any matchers:\n";
478 const char* outer_sep =
"";
480 outer_sep =
"\nand ";
482 for (
size_t ei = 0; ei < element_matched.size(); ++ei) {
483 if (element_matched[ei])
487 *listener << outer_sep << sep <<
"element #" << ei <<
": " 488 << element_printouts[ei];
GTEST_API_ string ConvertIdentifierNameToWords(const char *id_name)
internal::EqMatcher< T > Eq(T x)
::std::ostream * stream()
StreamCodecFactory stream
GTEST_API_ bool FindPairing(const MatchMatrix &matrix, MatchResultListener *listener)
bool HasEdge(size_t ilhs, size_t irhs) const
bool IsInterested() const
MaxBipartiteMatchState(const MatchMatrix &graph)
static const size_t kUnused
GTEST_API_ string JoinAsTuple(const Strings &fields)
::std::vector< ElementMatcherPair > ElementMatcherPairs
#define GTEST_DISALLOW_ASSIGN_(type)
std::unordered_set< std::pair< const IValidator *, const dynamic * > > seen
static void LogElementMatcherPairVec(const ElementMatcherPairs &pairs,::std::ostream *stream)
def Iter(n, format, sep='')
ElementMatcherPairs Compute()
bool TryAugment(size_t ilhs,::std::vector< char > *seen)
#define GTEST_CHECK_(condition)
::std::pair< size_t, size_t > ElementMatcherPair
GTEST_API_ string FormatMatcherDescription(bool negation, const char *matcher_name, const Strings ¶m_values)
GTEST_API_ ElementMatcherPairs FindMaxBipartiteMatching(const MatchMatrix &g)
::std::vector< string > Strings
Range< const char * > StringPiece