问题
I'm using the google test function EXPECT_EQ to run a test case for a function. The function, "find" returns a list and takes in a string of the name to find. Here's my test function:
TEST_F(test_neighborhood, find) {
list<Man> test;
test.push_back(Man("username", "John", "Smith", 1, 1, ""));
EXPECT_EQ(neighborhood.find("John"), test);
}
But when I try to "make", it gives me a long error /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:665:71: error: invalid operands to binary expression ('const Man' and 'const Man') bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
Am I not using EXPECT_EQ correctly? How do I fix this error?
回答1:
EXPECT_EQ
requires equality operator to be defined for passed items. std::list
already has such an operator calling equality operator for each stored item. So it seems that you need to define operator ==
to compare two instances of Man
class for equality:
bool operator ==(Man const & left, Man const & right)
来源:https://stackoverflow.com/questions/48289684/expect-eq-error