Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: provide a function to verify strict weak ordering #212

Open
GoogleCodeExporter opened this issue Jul 31, 2015 · 4 comments
Open

Comments

@GoogleCodeExporter
Copy link

Many algorithms (e.g. std::sort) require a binary comparator to be a strict
weak ordering, or the program may crash or result in corrupted memory.  It
would be very useful to provide a function template to verify that a
comparitor is a strict weak ordering:

  VerifyStrictWeakOrdering(comp, values);

will test comp on the given collection of values.  When a counter example
is found, the function will generate a failure and print the counter
example to help the user understand why comp is not an SWO.  The time
complexity of this function may be O(N^2) where N is the number of values.

Original issue reported on code.google.com by [email protected] on 2 Nov 2009 at 9:22

@GoogleCodeExporter
Copy link
Author

It's better done as a gmock matcher.

Original comment by [email protected] on 26 Feb 2010 at 8:03

  • Added labels: Priority-High
  • Removed labels: Priority-Medium

@GoogleCodeExporter
Copy link
Author

Original comment by [email protected] on 27 Sep 2010 at 7:11

@GoogleCodeExporter
Copy link
Author

Original comment by [email protected] on 28 Sep 2010 at 4:49

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

I have a solution almost finished that uses O(N) memory and
O(N^2) time.  It has sit there fore 6 months and I just have to find
the time to give it the final touch! ;-)

My solution is implemented as a googlemock matcher, such that you can
easily compose the predicate with other predicates, e.g.

 EXPECT_THAT(MyComparator(), IsSWO(some_array));
 EXPECT_THAT(MyComparator(), AnyOf(IsSWO(some_array), HasSomeOtherProperty()));

I'm not sure if the generality for allowing composition is really
needed, but it's nice to have that option. ;-)

Original comment by [email protected] on 28 Jan 2011 at 8:53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant