EXPECT_EQ Error

EXPECT_EQ Error

本文关键字:Error EQ EXPECT      更新时间:2023-10-16

我正在使用谷歌测试函数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);
}

但是当我试图"制造"时,它给了我一个很长的错误/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:665:71:错误:无效 二进制表达式的操作数("const Man"和"const Man"( bool operator(((const _T1& __x, const _T1& __y( const {return __x == __y;}

我没有正确使用EXPECT_EQ吗?如何修复此错误?

EXPECT_EQ要求为传递的项定义相等运算符。 std::list已经有这样一个运算符为每个存储项调用相等运算符。因此,您似乎需要定义operator ==来比较Man类的两个实例的相等性:

bool operator ==(Man const & left, Man const & right)
相关文章: