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

Enhancement: comparison between containers #231

Closed
GoogleCodeExporter opened this issue Jul 28, 2015 · 6 comments
Closed

Enhancement: comparison between containers #231

GoogleCodeExporter opened this issue Jul 28, 2015 · 6 comments

Comments

@GoogleCodeExporter
Copy link
Contributor

The google test framework includes no easy way to compare between containers of 
numbers. I have 
a potential solution that would be improved by inclusion in the googletest 
framework (and more 
direct access to the macros and templated functions).

I posted my solution on SO:
http://stackoverflow.com/questions/1460703/comparison-of-arrays-in-google-
test/1681550#1681550

and I'm attaching my own copy of the source.

Original issue reported on code.google.com by johnson.seth.r@gmail.com on 2 Dec 2009 at 2:18

Attachments:

@GoogleCodeExporter
Copy link
Contributor Author

Thanks for the contribution, Johnson.

In general, we try to avoid new macros as they are nasty.  Also, we encourage 
people
to use Google Mock, which is like a superset of Google Test.  Google Mock lets 
you
compare two containers like:

  EXPECT_THAT(my_container, ContainerEq(expected_container));

or (when the container is small):

  EXPECT_THAT(my_container, ElementsAre(1, 3, _, Lt(5)));
  // Element 1 must be 1; element 2 must be 3,
  // element 3 can be anything, and element 4 must be less than 5.

We may even move EXPECT_THAT and friends from Google Mock to Google Test in the
future.  Therefore we don't want to add new macros to do container comparison 
now.

Original comment by w...@google.com on 3 Dec 2009 at 4:45

  • Changed state: WontFix
  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Contributor Author

Thanks for the feedback. I wasn't aware of that framework.

Original comment by johnson.seth.r@gmail.com on 3 Dec 2009 at 4:52

@qcq
Copy link

qcq commented Oct 26, 2018

I want to ask another question, do we have a way to compare two containers which contains same items but not in same order.

@Bu11etmagnet
Copy link

We can compare them, but the answer will be "not equal".

@marthinsen
Copy link

marthinsen commented Oct 26, 2018

I want to ask another question, do we have a way to compare two containers which contains same items but not in same order.

There is a section about container matchers in the docs of Google Mock: https://github.com/google/googlemock/blob/master/googlemock/docs/v1_7/CheatSheet.md#container-matchers
EXPECT_THAT(my_container, UnorderedElementsAreArray(expected_container)); might help.

@qcq
Copy link

qcq commented Oct 29, 2018 via email

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

No branches or pull requests

4 participants