- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想要等于 2 个对象,正好是卡片(使用 gtest 进行单元测试)。这是我的代码:
#include "stdafx.h"
#include <gtest\gtest.h>
#include <vector>
class Card {
public:
Card(int value, int color) :value(value), color(color) {};
int returnColor() const { return color; };
int returnValue() const { return value; };
bool operator==(const Card &card) {
return returnValue() == card.returnValue();
};
private:
int value;
int color;
};
class CardTest : public ::testing::Test {
protected:
std::vector<Card> cards;
CardTest() { cards.push_back(Card(10, 2));
cards.push_back(Card(10, 3));
};
};
TEST_F(CardTest, firstTest)
{
EXPECT_EQ(cards.at(0), cards.at(1));
}
int main(int argc, char *argv[])
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
我有错误:
State Error C2678 binary '==': no operator found which takes a left-hand operand of type 'const Card' (or there is no acceptable conversion)
我尝试重载运算符“==”,但这不起作用:/也许,我必须走另一条路?这是我的第一个单元测试 :D。
最佳答案
相等运算符需要是const
:
bool operator==(const Card &card) const {
^^^^^
有关 const 方法的讨论,请参阅 Meaning of "const" last in a C++ method declaration?
关于c++ - Gtest,等于对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41402634/
我在尝试使用 cmake 构建项目时遇到错误。 我在我的电脑上手动下载并安装了 gtest(即/usr/include 中提供了 gtest 头文件)和/usr/lib 中的 gtest、gtest_
我在构建我的项目时遇到以下错误 C:\gtest\gtest-1.6.0\include\gtest/gtest-printers.h(327) : error C2220: warning trea
你好, 我目前正在研究 CMake,以便在工作中使用 ExternalProject_add。因为我想测试 googletest,所以我尝试同时测试两者。我在编译单元测试代码时遇到问题。 所以我就按照
我一直在为这个问题苦苦挣扎一段时间:我在 Windows 10 下使用 CMake 和 GTest,但我得到一个 (Link target) -> LINK : fatal error LNK1104
如果内存不足,C++ 中的 new 关键字将抛出异常,但下面的代码会在 new 失败时尝试返回“NO_MEMORY”。这很糟糕,因为它会引发 std::bad_alloc 异常。 我正在写一个单元测试
我正在尝试运行一些Google测试,并且在每个测试装置中都有很多代码需要重复,因此我想使代码尽可能简短,我想使用的子类的SetUp方法Testing::test父类,但是TEST_F固定装置无法识别S
我正在尝试使用 gtest 类型参数化来确保我的类的基本功能。但是我被困在测试设置中。以下是示例: 我有两个名为 CatTest 和 DogTest 的类,以及一个名为 AnimalTest 的基类,
我想应用参数化测试并具有以下夹具: class MyTest: public ::testing::TestWithParam {...}; 我想设置两个参数化测试用例,其中一个小参数失败,但大参数成
如果我使用 g(oogle)Test,这些像 FRIEND_TEST(Test, Proc) 这样的小谷歌宏在我的代码中随处可见。是否有自动机制将它们从构建中排除,或者我真的必须用 #ifdefs 包
我有一个项目,我添加了一个 gtest 项目,然后将原始项目转换为 .lib 项目,并从第三个新项目调用其 main() 函数。这样,我就可以用项目 .exe 构建测试 .exe。除了,它不起作用。
注意:我知道这个问题以不同的方式被问到,但我无法根据我的限制解决它: 我正在使用谷歌测试版 1.7 使用平台工具集 V100 在 Visual Studio 2010 中编译 我正在为我创建的库编写
我的项目中有一个目录树: /project /build /src main.cpp student.cpp /include
在我们所知的 gtets 中,当控件找到 TEST 或 TEST_F 函数时,它会注册 测试用例 进入 gtest。但是按照我的要求,gtest注册完所有的测试用例之后我需要搜索 testcasena
我有一大套单元测试和一些集成测试是用谷歌测试框架或 gtest 实现的。 由于没有标记,我使用禁用约定将测试分成组或在它们前面加上 GROUPA_、GROUPB_ 等前缀。 这很好用。我可以过滤不同的
我想混合参数化测试和类型化测试。这是我的尝试: struct X {}; struct Y {}; template struct MyTestFixture: public ::testing::
我已阅读 this official document ,了解如何进行二进制比较和字符串比较。 ASSERT_EQ 和 ASSERT_STREQ 在数组比较情况下无法工作。 例如 li@li:~/po
我正在测试我的功能是否正确运行 bool Core::IsMeta(void) { return mProc->GetCode(mPC)->Meta; } 使用说明 EXPECT_EQ(true,
我想用 gtest 测试一个模板类。我在 Google Test manual 中阅读了有关 TYPED_TEST 的信息并查看了official example他们引用了,但我仍然无法全神贯注地获取
这是我的: /* Can't change 'base' struct. */ struct base { public: template void printVal() {
我想要等于 2 个对象,正好是卡片(使用 gtest 进行单元测试)。这是我的代码: #include "stdafx.h" #include #include class Card { p
我是一名优秀的程序员,十分优秀!