gpt4 book ai didi

c++ - 排除时间测试

转载 作者:行者123 更新时间:2023-11-28 08:21:06 25 4
gpt4 key购买 nike

你好,我有一些类(class),例如“数学”:头文件:

class Math
{
public:
Math(void);
double returnPi();
~Math(void);
};

和cpp文件:

#include <windows.h>
#include "Math.h"

Math::Math(void)
{ Sleep(500) ;}

Math::~Math(void)
{ Sleep(500) ;}

double Math::returnPi()
{ Sleep(1000) ;
return 3.14159265;
}

我也测试了这个文件:

#include "..\gtest\gtest.h"
#include "Math.h"

TEST(Speed, Math)
{
Math *m=new Math();
EXPECT_LT(3.14,m->returnPi());
}

当我运行这个测试时,我看到测试通过并且这个测试的时间是 1500 毫秒,我如何从总测试时间中排除创建类所用的时间?

最佳答案

你就不能这样做吗?

#include "..\gtest\gtest.h"
#include "Math.h"

Math math;

TEST(Speed, Math)
{
Math *m=&math;
EXPECT_LT(3.14,m->returnPi());
}

关于c++ - 排除时间测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5815693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com