EXPECT_EQ错误 [英] EXPECT_EQ Error

查看:885
本文介绍了EXPECT_EQ错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google测试功能EXPECT_EQ来运行该功能的测试用例.函数"find"返回一个列表,并接受一个名称字符串来查找.这是我的测试功能:

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);
}

但是当我尝试制作"时,它给了我一个很长的错误 /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;}

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;}

我没有正确使用EXPECT_EQ吗?如何解决此错误?

Am I not using EXPECT_EQ correctly? How do I fix this error?

推荐答案

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

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)

这篇关于EXPECT_EQ错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆