EXPECT_EQ Error

孤街醉人 提交于 2020-01-16 08:51:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!