我正在使用谷歌测试函数EXPECT_EQ来运行函数的测试用例。函数" find“返回一个列表,并接受要查找的名称的字符串。下面是我的测试函数:
TEST_F(test_neighborhood, find) {
list<Man> test;
test.push_back(Man("username", "John", "Smith", 1, 1, ""));
EXPECT_EQ(neighborhood.find("John"), test);
}但当我尝试"make“时,它给出了一个很长的错误:对二进制表达式('const Man‘和'const Man')布尔运算符()( const _T1& __x,const _T1& __y) const{ /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:665:71:__x == __y;}的操作数无效。
我没有正确使用EXPECT_EQ吗?如何修复此错误?
发布于 2018-01-17 04:57:08
EXPECT_EQ要求为传递的项定义相等运算符。std::list已经有一个这样的运算符,为每个存储项调用相等运算符。因此,您似乎需要定义operator ==来比较Man类的两个实例是否相等:
bool operator ==(Man const & left, Man const & right)https://stackoverflow.com/questions/48289684
复制相似问题