当前位置: 首页 > news >正文

googleTest 源码主线框架性分析——TDD 01

TDD,测试驱动开发,英文全称Test-Driven Development,简称TDD,是一种不同于传统软件开发流程的新型的开发方法。它要求在编写某个功能的代码之前先编写测试代码,然后只编写使测试通过的功能代码,通过测试来推动整个开发的进行。这有助于编写简洁可用和高质量的代码,并加速开发过程。

简言之TDD是通过设计 Test 来完成软件设计的一种高效可行的软件开发模式。

为何更丰富地达成测试的目的,googletes是绕不过去的,本文备忘主要关注 googletest 主体的分析过程和结论,即,googleTest框架中是如何通过相关的测试宏的,实现测试的目的。

TEST TEST_F TEST_P 等等

1,googleTest 环境与简单示例

1.1 下载 googletest 并编译

下载:

$ git clone https://github.com/google/googletest.git
$ git checkout release-1.10.0

编译:

$ mkdir build
$ cd build/
$ export CXXFLAGS="-Wno-error=maybe-uninitialized"
$ cmake ..
$ make -j
$ ls lib/

 默认为 release,若debug版本则须:

$ cmake .. -DCMAKE_BUILD_TYPE=Debug

成果:

1.2 示例1 验证函数 add

源码

#include <iostream>
#include "gtest/gtest.h"int add_int_int(int a, int b){return a+b;
}TEST(SumFuncTest, twoNumbers){EXPECT_EQ(add_int_int(3,4),7);EXPECT_EQ(27, add_int_int(9, 18));
}GTEST_API_ int main(int argc, char** argv) {printf("Running main() from %s\n", __FILE__);testing::InitGoogleTest(&argc, argv);return RUN_ALL_TESTS();
}

运行:

1.3 示例 2

#include <gtest/gtest.h>int Foo(int a, int b)
{if (a == 0 || b == 0){throw "don't do that";}int c = a % b;if (c == 0)return b;return Foo(b, c);
}TEST(FooTest, HandleNoneZeroInput)
{EXPECT_EQ(2, Foo(4, 10));EXPECT_EQ(6, Foo(30, 18));
}

g++ foo.cpp -I ../../googletest/googletest/include -L ../../googletest/build_dbg/lib -lgtest -lgtest_main

编译运行:

1.4 示例3

源码:

#include <iostream>
#include "gtest/gtest.h"// add_util.ccfloat add_from_left(float a, float b, float c, float d,	float e)
{float sum = 0.0;sum += c;sum += a;sum += b;//sum += c;sum += d;sum += e;
/*sum += a;sum += b;sum += c;sum += d;sum += e;
*/printf("add_from_left: sum = %f\n", sum);return sum;
}float add_from_right(float a, float b, float c,	float d, float e)
{float sum = 0.0;sum += e;sum += d;sum += c;sum += b;sum += a;printf("add_from_right: sum = %f\n", sum);return sum;
}int sum(int a, int b){return a+b;
}TEST(AddFuncTest, floatVSfloat) {printf("AddFuncTest: float  sum = %f\n", 1.238f + 3.7f + 0.000353265f + 7898.3f + 12.23209f);printf("AddFuncTest: double sum = %f\n", 12.23209 + 7898.3 + 0.000353265 + 3.7 + 1.238);EXPECT_EQ(1.238f + 3.7f + 0.000353265f + 7898.3f + 12.23209f, add_from_left(1.238, 3.7, 0.000353265, 7898.3, 12.23209));EXPECT_EQ(1.238f + 3.7f + 0.000353265f + 7898.3f + 12.23209f, add_from_right(1.238, 3.7, 0.000353265, 7898.3, 12.23209));
//
}TEST(AddFuncTest, doubleVSfloat) {printf("AddFuncTest: float  sum = %f\n", 1.238f + 3.7f + 0.000353265f + 7898.3f + 12.23209f);printf("AddFuncTest: double sum = %f\n", 12.23209 + 7898.3 + 0.000353265 + 3.7 + 1.238);EXPECT_EQ(1.238f + 3.7f + 0.000353265f + 7898.3f + 12.23209f, add_from_left(1.238, 3.7, 0.000353265, 7898.3, 12.23209));EXPECT_EQ(1.238 + 3.7 + 0.000353265 + 7898.3 + 12.23209, add_from_right(1.238, 3.7, 0.000353265, 7898.3, 12.23209));
//
}TEST(SumFuncTest, twoNumbers){EXPECT_EQ(sum(3,4),7);EXPECT_EQ(27, sum(9, 18));
}GTEST_API_ int main(int argc, char** argv) {printf("Running main() from %s\n", __FILE__);testing::InitGoogleTest(&argc, argv);return RUN_ALL_TESTS();
}

Makefile

EXE := hello_gtest_ex hello_gtest_add_int_int
all: $(EXE)%: %.cppg++ -O0 -fno-toplevel-reorder $< -o $@ $(INC) $(LD_FLAGS)INC := -I../googletest/googletest/include/
LD_FLAGS := -L../googletest/build/lib/ -lgtest -lgtest_main.PHONY: clean
clean:-rm -rf $(EXE)

2,示例与源码分析

使用最简单的测试示例,聚焦googletest本身的代码逻辑

观察点,main 函数如何调用到 TEST(...){...} 这种结构中的代码

两种方式互相印证:

方式1,通过编译器的预编译指令 g++ -E ... 生成展开代码;

方式2,通过跟踪源代码,来份些TEST等的展开结果

2.1 TEST

示例代码如上:

simple_gtest.cpp


#include "gtest/gtest.h"int add_int_int(int a, int b){return a+b;
}TEST(SumFuncTest, twoNumbers){EXPECT_EQ(add_int_int(3,4),7);
}

方式1:

g++ -E simple_gtest.cpp -o simple_gtest.i

展开后,simple_gtest.i文件有8W多行,但是其中对我们理解有意义的也就最尾巴上的几行:


int add_int_int(int a, int b){return a+b;
}static_assert(sizeof("SumFuncTest") > 1, "test_suite_name must not be empty"); 
static_assert(sizeof("twoNumbers") > 1, "test_name must not be empty"); class SumFuncTest_twoNumbers_Test : public ::testing::Test { 
public: SumFuncTest_twoNumbers_Test() {} 
private:virtual void TestBody(); static ::testing::TestInfo* const test_info_ __attribute__ ((unused)); SumFuncTest_twoNumbers_Test(SumFuncTest_twoNumbers_Test const &) = delete; void operator=(SumFuncTest_twoNumbers_Test const &) = delete; 
}; ::testing::TestInfo* const SumFuncTest_twoNumbers_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "SumFuncTest", "twoNumbers", nullptr, nullptr, ::testing::internal::CodeLocation("simple_gtest.cpp", 8), (::testing::internal::GetTestTypeId()), ::testing::internal::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite("simple_gtest.cpp", 8), ::testing::internal::SuiteApiResolver< ::testing::Test>::GetTearDownCaseOrSuite("simple_gtest.cpp", 8), new ::testing::internal::TestFactoryImpl<SumFuncTest_twoNumbers_Test>); void SumFuncTest_twoNumbers_Test::TestBody()
{switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("add_int_int(3,4)", "7", add_int_int(3,4), 7))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "simple_gtest.cpp", 9, gtest_ar.failure_message()) = ::testing::Message();
}

分析这段代码会发现,

TEST被展开成为了一个 class SumFuncTest_twoNumbers_Test

它有一个成员函数 TestBody(){....}

观察上述代码中最后一个函数体:void SumFuncTest_twoNumbers_Test::TestBody()

其中出现了被测试的函数等。

这说明,这个函数体中的代码才是是被测试内容,而其外围都是框架。

框架部分只需要把这中类的一个实例添加到某个链表中,然后依次迭代执行每个类的 TestBody成员函数,既可以完成测试任务。

本例中的 class 如下:

通过方法2.来验证一下展开的结果:

第一部分,class 宏

关联TEST宏,我们可以找到如下内容:


#define TEST(test_suite_name, test_name) GTEST_TEST(test_suite_name, test_name)#define GTEST_TEST(test_suite_name, test_name)             \GTEST_TEST_(test_suite_name, test_name, ::testing::Test, \::testing::internal::GetTestTypeId())// Expands to the name of the class that implements the given test.
#define GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \test_suite_name##_##test_name##_Test// Helper macro for defining tests.
#define GTEST_TEST_(test_suite_name, test_name, parent_class, parent_id)       \static_assert(sizeof(GTEST_STRINGIFY_(test_suite_name)) > 1,                 \"test_suite_name must not be empty");                          \static_assert(sizeof(GTEST_STRINGIFY_(test_name)) > 1,                       \"test_name must not be empty");                                \class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)                     \: public parent_class {                                                  \public:                                                                     \GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() = default;            \~GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() override = default;  \GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)                         \(const GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) &) = delete;     \GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) & operator=(            \const GTEST_TEST_CLASS_NAME_(test_suite_name,                          \test_name) &) = delete; /* NOLINT */      \GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)                         \(GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) &&) noexcept = delete; \GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) & operator=(            \GTEST_TEST_CLASS_NAME_(test_suite_name,                                \test_name) &&) noexcept = delete; /* NOLINT */  \\private:                                                                    \void TestBody() override;                                                  \static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;      \};                                                                           \\::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_suite_name,           \test_name)::test_info_ =   \::testing::internal::MakeAndRegisterTestInfo(                            \#test_suite_name, #test_name, nullptr, nullptr,                      \::testing::internal::CodeLocation(__FILE__, __LINE__), (parent_id),  \::testing::internal::SuiteApiResolver<                               \parent_class>::GetSetUpCaseOrSuite(__FILE__, __LINE__),          \::testing::internal::SuiteApiResolver<                               \parent_class>::GetTearDownCaseOrSuite(__FILE__, __LINE__),       \new ::testing::internal::TestFactoryImpl<GTEST_TEST_CLASS_NAME_(     \test_suite_name, test_name)>);                                   \void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody()

其中的如下两行:

class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \

: public parent_class { \

TEST 的宏充分展开后,会根据TEST(X,Y) 括号中的X、Y字串定义一个完整的类,并且包含成员函数:
  TestBody()

但是展开的内容中,没有这个函数的函数体。

这个函数体正好就是TEST(X,Y){Z} 中,{Z}的这个部分,即,
 
  TestBody(){Z}

只需要在整个测试系统中,讲上面展开生成的class的一个实例,insert进一个链表中,并依次迭代执行链表的每一对象的成员函数 TestBody(){Z},即可达到测试目的。

第二部分,函数体中的宏

关于 EXPECT_EQ,我们会发现如下定义:

#define EXPECT_EQ(val1, val2) \EXPECT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)

而其中的 EXPECT_PRED_FORMAT2 又被展开为如下:

// Binary predicate assertion macros.
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)

又 GTEST_PRED_FORMAT2_ 被定义为:

#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure) \GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), on_failure)

而且其中的 GTEST_ASSERT_  被展开为:

#define GTEST_ASSERT_(expression, on_failure)                   \GTEST_AMBIGUOUS_ELSE_BLOCKER_                                 \if (const ::testing::AssertionResult gtest_ar = (expression)) \;                                                           \else                                                          \on_failure(gtest_ar.failure_message())

其中 GTEST_AMBIGUOUS_ELSE_BLOCKER_ 展开为:

#define GTEST_AMBIGUOUS_ELSE_BLOCKER_ \switch (0)                          \case 0:                             \default:  // NOLINT

于是得到函数体为:

总之,只需要调用这个 TestBody() 函数,即可完成测试任务。

2.2 TEST_F

2.2.1 小示例编译与运行

保持关于 TEST 宏分析的记忆,我们以一个简单的示例来分析 TEST_F 宏,

#include <gtest/gtest.h>class SampleTestWithFixture : public ::testing::Test {
protected:void SetUp() override {a_ = 1;b_ = 2;}int a_;int b_;
};TEST_F(SampleTestWithFixture, Case2) {a_ = 3;EXPECT_EQ(a_ + b_, 5);
}

Makefile:

EXE := hello_gtest_f
all: $(EXE)%: %.cppg++ -g -fno-toplevel-reorder $< -o $@ $(INC) $(LD_FLAGS)# g++ -E hello_gtest_f.cpp  -I ../googletest/googletest/include/ -o hello_gtest_f.i
#g++ -g -fno-toplevel-reorder $< -o $@ $(INC) $(LD_FLAGS)INC := -I../../googletest/googletest/include/
LD_FLAGS := -L../../googletest/build_dbg/lib/ -lgtest -lgtest_main.PHONY: clean
clean:-rm -rf $(EXE)

编译,确保能够正确运行:

$ make

$ ./hello_gtest_f

2.2.2 TEST_F 宏展开分析

$ g++ -E hello_gtest_f.cpp  -I ../googletest/googletest/include/ -o hello_gtest_f.i

生成的预处理后的文件 hello_gtest_f.i 主要内容还是在文件的尾巴上,摘录调整格式如下:

class SampleTestWithFixture : public ::testing::Test {
protected:void SetUp() override {a_ = 1;b_ = 2;}int a_;int b_;
};static_assert(sizeof("SampleTestWithFixture") > 1, "test_suite_name must not be empty");
static_assert(sizeof("Case2") > 1, "test_name must not be empty");class SampleTestWithFixture_Case2_Test : public SampleTestWithFixture{
public:SampleTestWithFixture_Case2_Test() = default;~SampleTestWithFixture_Case2_Test() override = default;SampleTestWithFixture_Case2_Test(const SampleTestWithFixture_Case2_Test&) = delete;SampleTestWithFixture_Case2_Test& operator=( const SampleTestWithFixture_Case2_Test&) = delete;SampleTestWithFixture_Case2_Test(SampleTestWithFixture_Case2_Test &&) noexcept = delete;SampleTestWithFixture_Case2_Test& operator=(SampleTestWithFixture_Case2_Test &&) noexcept = delete;private: void TestBody() override;static ::testing::TestInfo* const test_info_ __attribute__((unused));
};::testing::TestInfo* const SampleTestWithFixture_Case2_Test::test_info_=::testing::internal::MakeAndRegisterTestInfo("SampleTestWithFixture","Case2",nullptr,nullptr,::testing::internal::CodeLocation("hello_gtest_f.cpp", 27),(::testing::internal::GetTypeId<SampleTestWithFixture>()),::testing::internal::SuiteApiResolver< SampleTestWithFixture>::GetSetUpCaseOrSuite("hello_gtest_f.cpp", 27),::testing::internal::SuiteApiResolver< SampleTestWithFixture>::GetTearDownCaseOrSuite("hello_gtest_f.cpp", 27),new ::testing::internal::TestFactoryImpl<SampleTestWithFixture_Case2_Test>);void SampleTestWithFixture_Case2_Test::TestBody()
{a_ = 3;switch (0)case 0:default:if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare( "a_ + b_" ,  "5" ,  a_ + b_ ,  5 )));else::testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "hello_gtest_f.cpp", 29, gtest_ar.failure_message())= ::testing::Message();
}

跟 TEST 宏的展开类似,组合 TEST_F(X,Y) 的两个参数,构成一个新的类

class X_Y_Test :public SampleTestWithFixture{

...

... TestBody()

}

宏展开的新类中也有一个成员函数 TestBody();

其中 SampleTestWithFixture 是自己定义的类,会被 X_Y_Test 类共有继承走。

而 TEST_F(...){body} 的类似函数体的部分 {body},也同样被安排成为了 TestBody函数的函数体。

接下来,gtest框架会通过成员 X_Y_Test::test_info_ 的静态赋值过程,将本测试用例挂进系统的代运行链表,届时依次迭代 调用 X_Y_Test::TestBody(); 实现测试感兴趣代码的目的。

2.2.3 总结 TEST_F

TEST_F的意图:

TEST_F的目的是为了把关系密切的测试问题汇总到一个class中来进行测试,可以共用同一个类的对象的上下文成员数据。

TEST_F 中,成员函数的执行顺序:

那么,成员函数 Setup( ) 在什么时候执行呢?

先说答案:

  1      X_Y_Test() 构造函数;//c++ 语法

  2      Setup();                      //数据预备,资源申请

  3      TestBody();                //测试部分

  4      TearDown();               //资源释放

  5      X_Y_Test() 析构函数;//c++ 语法

改造刚才的示例:

#include <gtest/gtest.h>class SampleTestWithFixture : public ::testing::Test {
public:
SampleTestWithFixture(){std::cout<<"construct_STWF"<<std::endl;}
~SampleTestWithFixture(){std::cout<<"destruct_STWF"<<std::endl;}
protected:void SetUp() override {std::cout <<"Hello setupupup()000"<<std::endl;a_ = 1;b_ = 2;std::cout <<"Hello setupupup()111"<<std::endl;}void TearDown() override {std::cout <<"Hello teardownnn()000"<<std::endl;a_ = 4;b_ = 5;std::cout <<"Hello teardownnn()111"<<std::endl;}int a_;int b_;
};TEST_F(SampleTestWithFixture, Case2) {std::cout <<"test_f Casess222"<<std::endl;a_ = 3;EXPECT_EQ(a_ + b_, 5);
}

编译运行:

TEST_F函数体中的部分的一些宏,跟TEST中的一样,展开成为一些比较语句。

2.3 TEST_P

2.3.1 可运行示例

#include "gtest/gtest.h"namespace TTT
{
namespace testing
{
int g_env_switch = 0;class BasicTestFixture : public ::testing::TestWithParam<int>
{
public:BasicTestFixture() {}void SetUp(){g_env_switch = GetParam();std::cout<<"BTF_SetUp() ges="<<g_env_switch<<std::endl;}void TearDown(){}
};#define OK 0
#define FAIL 1int envCheckFunc(void)
{if(g_env_switch > 0) {return OK;}else {return FAIL;}
}TEST_P(BasicTestFixture, BasicTest)
{ASSERT_EQ(envCheckFunc(), OK);
}INSTANTIATE_TEST_SUITE_P(configSwitch, BasicTestFixture, ::testing::Values(1, 0));
//INSTANTIATE_TEST_SUITE_P(failSwitch, BasicTestFixture, ::testing::Values(2, 3));}
}

Makefile:

EXE := hello_gtest_pall: $(EXE)%: %.cppg++ -g -fno-toplevel-reorder $< -o $@ $(INC) $(LD_FLAGS)# g++ -E hello_gtest_p.cpp  -I ../googletest/googletest/include/ -o hello_gtest_p.i
#g++ -g -fno-toplevel-reorder $< -o $@ $(INC) $(LD_FLAGS)INC := -I../../googletest/googletest/include/
LD_FLAGS := -L../../googletest/build_dbg/lib/ -lgtest -lgtest_main.PHONY: clean
clean:-rm -rf $(EXE)

编译执行:

因为故意藏了一个逻辑错误,所以第二个参数时,会测试失败:

2.3.2 无实例化宏的预编译

注释掉程序中的所有 INSTANTIATE_TEST_SUITE_P 的行,不厌其烦地再贴一次:

#include "gtest/gtest.h"namespace TTT
{
namespace testing
{
int g_env_switch = 0;class BasicTestFixture : public ::testing::TestWithParam<int>
{
public:BasicTestFixture() {}void SetUp(){g_env_switch = GetParam();std::cout<<"BTF_SetUp() ges="<<g_env_switch<<std::endl;}void TearDown(){}
};#define OK 0
#define FAIL 1int envCheckFunc(void)
{if(g_env_switch > 0) {return OK;}else {return FAIL;}
}TEST_P(BasicTestFixture, BasicTest)
{ASSERT_EQ(envCheckFunc(), OK);
}//INSTANTIATE_TEST_SUITE_P(configSwitch, BasicTestFixture, ::testing::Values(1, 0));
//INSTANTIATE_TEST_SUITE_P(failSwitch, BasicTestFixture, ::testing::Values(2, 3));}
}

g++ -E hello_gtest_p.cpp -I ../googletest/googletest/include/ -o hello_gtest_p.i

这时候预编译后生成的代码如下:

namespace TTT
{
namespace testing
{
int g_env_switch = 0;class BasicTestFixture : public ::testing::TestWithParam<int>
{
public:BasicTestFixture() {}void SetUp(){g_env_switch = GetParam();std::cout<<"BTF_SetUp() ges="<<g_env_switch<<std::endl;}void TearDown(){}
};int envCheckFunc(void)
{if(g_env_switch > 0) {return 0;}else {return 1;}
}class BasicTestFixture_BasicTest_Test : public BasicTestFixture, private ::testing::internal::GTestNonCopyable {
public:BasicTestFixture_BasicTest_Test() {}void TestBody() override;
private:static int AddToRegistry(){::testing::UnitTest::GetInstance()->parameterized_test_registry().GetTestSuitePatternHolder<BasicTestFixture>( "BasicTestFixture", ::testing::internal::CodeLocation("hello_gtest_p.cpp", 35))->AddTestPattern( "BasicTestFixture","BasicTest",new ::testing::internal::TestMetaFactory<BasicTestFixture_BasicTest_Test>(),::testing::internal::CodeLocation("hello_gtest_p.cpp", 35));return 0;}static int gtest_registering_dummy_ __attribute__((unused));
};int BasicTestFixture_BasicTest_Test::gtest_registering_dummy_ = BasicTestFixture_BasicTest_Test::AddToRegistry();void BasicTestFixture_BasicTest_Test::TestBody()
{switch (0)case 0:default:if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("envCheckFunc()", "0", envCheckFunc(), 0)));elsereturn ::testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure, "hello_gtest_p.cpp", 37, gtest_ar.failure_message()) = ::testing::Message();
}

没有实例化宏 的代码,展开到被测试类的 TestBody()函数后就停止了,如上代码中最后一个函数的定义。

2.3.3 有实例化宏的预编译

多了这两句:

INSTANTIATE_TEST_SUITE_P(configSwitch, BasicTestFixture, ::testing::Values(1, 0));

INSTANTIATE_TEST_SUITE_P(failSwitch, BasicTestFixture, ::testing::Values(2, 3));


namespace TTT
{
namespace testing
{
int g_env_switch = 0;class BasicTestFixture : public ::testing::TestWithParam<int>
{
public:BasicTestFixture() {}void SetUp(){g_env_switch = GetParam();std::cout<<"BTF_SetUp() ges="<<g_env_switch<<std::endl;}void TearDown(){}
};int envCheckFunc(void)
{if(g_env_switch > 0) {return 0;}else {return 1;}
}class BasicTestFixture_BasicTest_Test : public BasicTestFixture, private ::testing::internal::GTestNonCopyable {
public:BasicTestFixture_BasicTest_Test() {}void TestBody() override;private:static int AddToRegistry(){::testing::UnitTest::GetInstance()->parameterized_test_registry().GetTestSuitePatternHolder<BasicTestFixture>( "BasicTestFixture", ::testing::internal::CodeLocation("hello_gtest_p.cpp", 35))->AddTestPattern( "BasicTestFixture","BasicTest",new ::testing::internal::TestMetaFactory<BasicTestFixture_BasicTest_Test>(),::testing::internal::CodeLocation("hello_gtest_p.cpp",35));return 0;}static int gtest_registering_dummy_ __attribute__((unused));
};int BasicTestFixture_BasicTest_Test::gtest_registering_dummy_ = BasicTestFixture_BasicTest_Test::AddToRegistry();
void BasicTestFixture_BasicTest_Test::TestBody()
{switch (0)case 0:default:if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare( "envCheckFunc()", "0", envCheckFunc(), 0)));elsereturn ::testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure, "hello_gtest_p.cpp", 37, gtest_ar.failure_message()) = ::testing::Message();
}
//TEST_P(X, Y, ...){}
// 跟 TEST_F的展开比较接近,同样是将 TEST_P(){...} 的{...} 部分,作为TestBody的函数体;
// 但,一个重要不懂的地方在于,TEST_P 展开为被测试模式或模版,真正注册近被执行队列,是INSTANTIATE_TEST_SUITE_P的工作。//INSTANTIATE_TEST_SUITE_P(X, Y, ...)的展开位三个函数
//参数容器函数:gtest_XY_EvaluGenerator_    测试参数值;
//被测试类函数:gtest_XY_EvalGenerateName_  测试参数类型;
//测试类压栈函数:gtest_XY_dummy_           将测试类实例化后 push进带测试队列中,通过调用 AddTestSuiteInstantiation//展开,INSTANTIATE_TEST_SUITE_P(configSwitch, BasicTestFixture, ::testing::Values(1, 0));static ::testing::internal::ParamGenerator<BasicTestFixture::ParamType> gtest_configSwitchBasicTestFixture_EvalGenerator_()
{return::testing::Values(1, 0);
}static ::std::string gtest_configSwitchBasicTestFixture_EvalGenerateName_( const ::testing::TestParamInfo<BasicTestFixture::ParamType>& info)
{if (::testing::internal::AlwaysFalse()) {::testing::internal::TestNotEmpty(::testing::internal::DefaultParamName<BasicTestFixture::ParamType>);auto t = std::make_tuple(::testing::Values(1, 0));static_assert(std::tuple_size<decltype(t)>::value <= 2, "Too Many Args!");}return ((::testing::internal::DefaultParamName<BasicTestFixture::ParamType>))(info);
}static int gtest_configSwitchBasicTestFixture_dummy_ __attribute__((unused))= ::testing::UnitTest::GetInstance()->parameterized_test_registry().GetTestSuitePatternHolder<BasicTestFixture>("BasicTestFixture", ::testing::internal::CodeLocation("hello_gtest_p.cpp", 40))->AddTestSuiteInstantiation("configSwitch",&gtest_configSwitchBasicTestFixture_EvalGenerator_,&gtest_configSwitchBasicTestFixture_EvalGenerateName_,"hello_gtest_p.cpp",40);//展开,INSTANTIATE_TEST_SUITE_P(failSwitch, BasicTestFixture, ::testing::Values(2, 3));static ::testing::internal::ParamGenerator<BasicTestFixture::ParamType> gtest_failSwitchBasicTestFixture_EvalGenerator_()
{return::testing::Values(2, 3);
}static ::std::string gtest_failSwitchBasicTestFixture_EvalGenerateName_( const ::testing::TestParamInfo<BasicTestFixture::ParamType>& info)
{if (::testing::internal::AlwaysFalse()) {::testing::internal::TestNotEmpty(::testing::internal::DefaultParamName<BasicTestFixture::ParamType>);auto t = std::make_tuple(::testing::Values(2, 3));static_assert(std::tuple_size<decltype(t)>::value <= 2, "Too Many Args!");}return ((::testing::internal::DefaultParamName<BasicTestFixture::ParamType>))(info);
}static int gtest_failSwitchBasicTestFixture_dummy_ __attribute__((unused))= ::testing::UnitTest::GetInstance()->parameterized_test_registry().GetTestSuitePatternHolder<BasicTestFixture>("BasicTestFixture", ::testing::internal::CodeLocation("hello_gtest_p.cpp", 41))->AddTestSuiteInstantiation("failSwitch",&gtest_failSwitchBasicTestFixture_EvalGenerator_,&gtest_failSwitchBasicTestFixture_EvalGenerateName_,"hello_gtest_p.cpp",41);}
}

2.3.4 分析 TEST_P 和

TEST_P(X, Y, ...){...}的展开 跟 TEST_F的展开比较接近,继承用户自定义类后,定义一个新类,含有成员函数 TestBody,同样是将 TEST_P(){...} 的{...} 部分,作为TestBody的函数体;

但,一个重要不同的地方在于,TEST_P 展开为被测试模式或模版,真正注册近被执行队列,是INSTANTIATE_TEST_SUITE_P的工作。

INSTANTIATE_TEST_SUITE_P(X, Y, ...)的展开位三个函数

1,参数容器函数:gtest_XY_EvaluGenerator_ 测试参数值;

2,被测试类函数:gtest_XY_EvalGenerateName_ 测试参数类型;

3,测试类压栈函数:gtest_XY_dummy_ 将测试类实例化后 push进带测试队列中,通过调用 AddTestSuiteInstantiation,压栈入队,等待main函数依次迭代调用各个类实例的 TestBody()成员函数,完成测试任务。

而其中的SetUp(), TearDown()等成员函数的调用,跟TEST_F的调用时机相同。

3. 总结

掌握 googletest的使用,
首先需要理解,TESTXXX(){...}结构中,{...}会被展开为一个类的成员函数 TestBody(){...} 的函数体。
其次,掌握Setup,TearDown的调用时机;
然后,对各种判别宏有一定掌握,比如 EXPECT_EQ;
最后,掌握 TEST_P de 参数的各种形式的使用方式

相关文章:

googleTest 源码主线框架性分析——TDD 01

TDD&#xff0c;测试驱动开发&#xff0c;英文全称Test-Driven Development&#xff0c;简称TDD&#xff0c;是一种不同于传统软件开发流程的新型的开发方法。它要求在编写某个功能的代码之前先编写测试代码&#xff0c;然后只编写使测试通过的功能代码&#xff0c;通过测试来推…...

Python:对常见报错导致的崩溃的处理

Python的注释&#xff1a; mac用cmd/即可 # 注释内容 代码正常运行会报以0退出&#xff0c;如果是1&#xff0c;则表示代码崩溃 age int(input(Age: )) print(age) 如果输入非数字&#xff0c;程序会崩溃&#xff0c;也就是破坏了程序&#xff0c;终止运行 解决方案&#xf…...

linux系统进程占cpu 100%解决步骤

1.查找进程 ps aux 查看指定进程: ps aux | grep process_name2.根据进程查找对应的主进程 pstree -p | grep process_name 3.查看主进程目录并删除 ps -axu | grep process_name rm -rf /usr/bin/2cbbb...

数据传输安全--IPSEC

目录 IPSEC IPSEC可以提供的安全服务 IPSEC 协议簇 两种工作模式 传输模式 隧道模式 两个通信保护协议&#xff08;两个安全协议&#xff09; AH&#xff08;鉴别头协议&#xff09; 可以提供的安全服务 报头 安全索引参数SPI 序列号 认证数据 AH保护范围 传输模…...

Unity XR Interaction Toolkit的安装(二)

提示&#xff1a;文章有错误的地方&#xff0c;还望诸位大神不吝指教&#xff01; 文章目录 前言一、安装1.打开unity项目2.打开包管理器&#xff08;PackageManage&#xff09;3.导入Input System依赖包4.Interaction Layers unity设置总结 前言 安装前请注意&#xff1a;需要…...

什么是PCB流锡槽焊盘/C型焊盘,如何设计?-捷配笔记

在PCB进行机器组装器件时&#xff08;如波峰焊&#xff09;&#xff0c;为了防止部分需要二次焊接的元器件的焊盘堵孔&#xff0c;就需要在PCB焊盘上面开个过锡槽&#xff0c;以便过波峰焊时&#xff0c;这些焊锡会流掉。开流锡槽就是在焊盘裸铜&#xff08;敷锡&#xff09;部…...

电缆故障精准定位系统

简介 电缆故障精准定位系统应用于35~500kV电压等级电缆线路故障精准定位与故障识别。基于百兆高速采样、北斗高精度授时、信号相位误差精确校准等 先进技术的应用&#xff0c;其定位精度小于5米&#xff0c;业内领先。 基于人工智能深度学习算法核心模块可自动、 快速进行故障…...

Google Chrome 浏览器在链接上点右键的快捷键

如今&#xff0c;越来越多的软件都懒得设个快捷键&#xff0c;就算设置了连个下划线也懒得加了。 谷歌浏览器右键 > 链接另存为... 和 复制链接地址 的快捷键 (如图)...

Redis在SpringBoot中遇到的问题:预热,雪崩,击穿,穿透

缓存预热 预热即在产品上线前&#xff0c;先对产品进行访问或者对产品的Redis中存储数据。 原因&#xff1a; 1. 请求数量较高 2. 主从之间数据吞吐量较大&#xff0c;数据同步操作频度较高,因为刚刚启动时&#xff0c;缓存中没有任何数据 解决方法&#xff1a; 1. 使用脚…...

Pytorch 6

罗切斯特回归模型 加了激活函数 加了激活函数之后类 class LogisticRegressionModel(torch.nn.Module):def __init__(self):super(LogisticRegressionModel, self).__init__()self.linear torch.nn.Linear(1,1)def forward(self, x):# y_pred F.sigmoid(self.linear(x))y_p…...

iterator(迭代器模式)

引入 在想显示数组当中所有元素时&#xff0c;我们往往会使用下面的for循环语句来遍历数组 #include <iostream> #include <vector>int main() {std::vector<int> v({ 1, 2, 3 });for (int i 0; i < v.size(); i){std::cout << v[i] << &q…...

使用Web控制端和轻量级客户端构建的开放Web应用防火墙(OpenWAF)

目录 1. 简介2. 项目结构3. Web控制端3.1. 功能概述3.2. 审计&#xff08;攻击&#xff09;日志查看3.3. 多个WAF的集中监控和操作3.4. 使用socket进行封装3.5. 日志的高效存储和检索&#xff08;Redis&#xff09; 4. 轻量级客户端4.1. 功能概述4.2. 对Web程序的防护4.3. 网络…...

设计模式在FileBrowser中的几个应用

设计模式是代码重构的最终目标&#xff0c;在程序设计中有效的运用这项技术&#xff0c;可以大大提高代码的可读性和可维护性。使整个程序设计结构趋向精致完美。在我维护的FileBrowser模块中可以针对以下方面 应用相应的模式。 1. 使用策略模式来处理文件夹扫描操作 作为网…...

【JavaEE进阶】——Spring AOP

目录 &#x1f6a9;Spring AOP概述 &#x1f6a9;Spring AOP快速⼊⻔ &#x1f393;引入AOP依赖 &#x1f393;编写AOP程序 &#x1f6a9;Spring AOP 详解 &#x1f393;Spring AOP核⼼概念 &#x1f393;通知类型 &#x1f393;PointCut &#x1f393;切⾯优先级 Ord…...

Python - conda使用大全

如何使用Conda&#xff1f; 环境 创建环境 conda create -n spider_env python3.10.11查看环境 conda env listconda info -e激活环境 conda activate spider_env退出环境 conda deactivate删除环境 conda env remove -n spider_env包 导出包 说明&#xff1a;导出当前虚拟…...

ASPICE在汽车软件开发中的作用

ASPICE是一个专门为汽车软件开发过程而设计的评估和改进框架。它基于ISO/IEC 15504标准&#xff0c;为汽车供应商提供了一个评估和改进其软件开发流程的方法。ASPICE的目标是确保软件开发过程的一致性和可预测性&#xff0c;从而提高软件的质量和可靠性。 ASPICE的实施对汽车软…...

亚马逊云科技 re:Inforce 2024中国站大会

亚马逊云科技 re:Inforce 2024中国站大会 - 生成式AI时代的全面安全&#xff0c;将于7月25日本周四在北京富力万丽酒店揭幕...

Lottie:动态动画的魔法棒

文章目录 引言官网链接Lottie 的原理基础使用1. 导出动画2. 引入 Lottie 库3. 加载和播放动画 高级使用1. 动画控制2. 交互性3. 自定义动画例子&#xff1a;交互式按钮动画 优缺点优点缺点 结语 引言 Lottie 是 Airbnb 开源的一个动画库&#xff0c;它允许设计师在 Adobe Afte…...

IPython使用技巧整理

IPython 是一个增强的 Python 交互式 shell&#xff0c;它提供了许多便利的功能&#xff0c;比如自动补全、魔术命令、对象内省等。以下是 IPython 的一些使用技巧和示例&#xff0c;结合您提供的列表数据&#xff0c;我将给出一些相关的使用示例。 1. 自动补全&#xff08;Tab…...

C#数组复习

一、一维数组 using System.Collections; using System.Collections.Generic; using UnityEngine;public class ShuZu : MonoBehaviour {#region 知识点一 基本概念//数组是存储一组相同类型数据的集合//数组分为 一维、二维、交错数组//一般情况 一维数组 就简称为数组#en…...

无人机之在农业上的用途

随着无人机技术的发展&#xff0c;农业现代化也迎来了崭新局面&#xff0c;田间随处可见无人机矫健的身影。当农业遇上科技&#xff0c;变革正悄然进行。农业无人机主要应用于农业、种植业、林业等行业。在使用过程中&#xff0c;其功能和作用并不单一&#xff0c;一般用于种植…...

opengaussdb在oepnEuler上安装

安装前提&#xff1a; 软件环境&#xff1a;openEuler 20.03LTS 个人开发者最低配置2核4G&#xff0c;推荐配置4核8G 数据库版本&#xff1a;openGauss-5.0.2-openEuler-64bit-all.tar.gz 数据库下载地址&#xff1a; https://docs-opengauss.osinfra.cn/zh/docs/5.0.0/docs/In…...

一些和颜色相关网站

1.中国传统色 2.网页颜色选择器 3.渐变色网站 4.多风格色卡生成 5.波浪生成 6.半透明磨砂框 7.色卡组合...

Linux系统编程-文件系统

目录 什么是Linux文件系统 文件系统的职责 存储介质抽象 inode&#xff1a;文件系统的核心 文件分配策略 目录结构 文件系统布局 日志和恢复机制 目录权限 粘滞位(t位)&#xff1a; 硬链接和符号链接 硬链接的特点&#xff1a; 创建硬链接&#xff1a; 符号链接的…...

【解决】ubuntu20.04 root用户无法SSH登陆问题

Ubuntu root用户无法登录的问题通常可以通过修改‌SSH配置文件和系统登录配置来解决。 修改SSH配置文件 sudo vim /etc/ssh/sshd_config 找到 PermitRootLogin 设置&#xff0c;并将其值更改为 yes 以允许root用户通过SSH登录 保存并关闭文件之后&#xff0c;需要重启SSH服务…...

(前缀和) LeetCode 238. 除自身以外数组的乘积

一. 题目描述 原题链接 给你一个整数数组 nums&#xff0c;返回 数组 answer &#xff0c;其中 answer[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积 。 题目数据 保证 数组 nums之中任意元素的全部前缀元素和后缀的乘积都在 32 位 整数范围内。 请 不要使用除法&…...

【JVM基础05】——组成-能不能解释一下方法区?

目录 1- 引言&#xff1a;方法区概述1-1 方法区是什么&#xff1f;(What)1-2 为什么用方法区&#xff1f;方法区的作用 (Why) 2- ⭐核心&#xff1a;详解方法区(How)2-1 能不能解释一下方法区&#xff1f;2-2 元空间内存溢出问题2-3 什么是常量池&#xff1f;2-4 运行时常量池 …...

前端:Vue学习-3

前端&#xff1a;Vue学习-3 1. 自定义指令2. 插槽2.1 插槽 - 后备内容&#xff08;默认值&#xff09;2.2 插槽 - 具名插槽2.3 插槽 - 作用域插槽 3. Vue - 路由3.1 路由模块封装3.2 声明式导航 router-link 高亮3.3 自定义匹配的类名3.4 声明式导肮 - 跳转传参3.5 Vue路由 - 重…...

npm 安装报错(已解决)+ 运行 “wue-cli-service”不是内部或外部命令,也不是可运行的程序(已解决)

首先先说一下我这个项目是3年前的一个项目了&#xff0c;中间也是经过了多个人的修改惨咋了布置多少个人的思想&#xff0c;这这道我手里直接npm都安装不上&#xff0c;在网上也查询了多种方法&#xff0c;终于是找到问题所在了 问题1&#xff1a; 先是npm i 报错在下面图片&…...

江苏科技大学24计算机考研数据速览,有专硕复试线大幅下降67分!

江苏科技大学&#xff08;Jiangsu University of Science and Technology&#xff09;&#xff0c;坐落在江苏省镇江市&#xff0c;是江苏省重点建设高校&#xff0c;江苏省人民政府与中国船舶集团有限公司共建高校&#xff0c;国家国防科技工业局与江苏省人民政府共建高校 &am…...

20分钟上手新版Skywalking 9.x APM监控系统

Skywalking https://skywalking.apache.org/ Skywalking是专为微服务、云原生和基于容器的&#xff08;Kubernetes&#xff09;架构设计的分布式系统性能监控工具。 Skywalking关键特性 ● 分布式跟踪 ○ 端到端分布式跟踪。服务拓扑分析、以服务为中心的可观察性和API仪表板。…...

【07】LLaMA-Factory微调大模型——微调模型导出与微调参数分析

上文介绍了如何对微调后的模型进行使用与简单评估。本文将介绍对微调后的模型进行导出的过程。 一、llama-3微调后的模型导出 首先进入虚拟环境&#xff0c;打开LLaMA-Factory的webui页面 conda activate GLM cd LLaMA-Factory llamafactory-cli webui 之后&#xff0c;选择…...

动态路由协议 —— EIGRP 与 OSPF 的区别

EIGRP&#xff08;增强内部网关路由协议&#xff09;和 OSPF&#xff08;开放式最短路径优先&#xff09;是两种最常见的动态路由协议&#xff0c;主要是用来指定路由器或交换机之间如何通信。将其应用于不同的情况下&#xff0c;可提高速率、延迟等方面的性能。那么它们之间到…...

【中项】系统集成项目管理工程师-第5章 软件工程-5.1软件工程定义与5.2软件需求

前言&#xff1a;系统集成项目管理工程师专业&#xff0c;现分享一些教材知识点。觉得文章还不错的喜欢点赞收藏的同时帮忙点点关注。 软考同样是国家人社部和工信部组织的国家级考试&#xff0c;全称为“全国计算机与软件专业技术资格&#xff08;水平&#xff09;考试”&…...

HarmonyOS应用开发者高级认证,Next版本发布后最新题库 - 多选题序号1

基础认证题库请移步&#xff1a;HarmonyOS应用开发者基础认证题库 注&#xff1a;有读者反馈&#xff0c;题库的代码块比较多&#xff0c;打开文章时会卡死。所以笔者将题库拆分&#xff0c;单选题20个为一组&#xff0c;多选题10个为一组&#xff0c;题库目录如下&#xff0c;…...

Windows11(24H2)LTSC长期版下载!提前曝光Build26100?

系统&#xff1b;windows11 文章目录 前言一、LTSC是什么&#xff1f;二、 Windows 11 Vision 24H2 LTSC 的版本号为 Build 26100&#xff0c;镜像中提供以下三个 SKU&#xff1a;总结 前言 好的系统也能给你带来不一样的效果。 一、LTSC是什么&#xff1f; & & L…...

【北京迅为】《i.MX8MM嵌入式Linux开发指南》-第三篇 嵌入式Linux驱动开发篇-第四十三章 驱动模块传参

i.MX8MM处理器采用了先进的14LPCFinFET工艺&#xff0c;提供更快的速度和更高的电源效率;四核Cortex-A53&#xff0c;单核Cortex-M4&#xff0c;多达五个内核 &#xff0c;主频高达1.8GHz&#xff0c;2G DDR4内存、8G EMMC存储。千兆工业级以太网、MIPI-DSI、USB HOST、WIFI/BT…...

uniapp 小程序 支付逻辑处理

uniapp 小程序 支付逻辑处理 上代码如果你不需要支付宝适配&#xff0c;可以删除掉支付宝的条件判断代码 <button class"subBtn" :disabled"submiting" click"goPay">去支付</button>// 以下代码你需要改的地方// 1. order/app/v1…...

scikit-learn库学习之make_regression函数

scikit-learn库学习之make_regression函数 一、简介 make_regression是scikit-learn库中用于生成回归问题数据集的函数。它主要用于创建合成的回归数据集&#xff0c;以便在算法的开发和测试中使用。 二、语法和参数 sklearn.datasets.make_regression(n_samples100, n_feat…...

经典文献阅读之--World Models for Autonomous Driving(自动驾驶的世界模型:综述)

Tip: 如果你在进行深度学习、自动驾驶、模型推理、微调或AI绘画出图等任务&#xff0c;并且需要GPU资源&#xff0c;可以考虑使用UCloud云计算旗下的Compshare的GPU算力云平台。他们提供高性价比的4090 GPU&#xff0c;按时收费每卡2.6元&#xff0c;月卡只需要1.7元每小时&…...

孙健提到的实验室的研究方向之一是什么?()

孙健提到的实验室的研究方向之一是什么?&#xff08;&#xff09; 点击查看答案 A.虚拟现实B.环境感知和理解 C.智能体博弈D.所有选项都正确 图灵奖是在哪一年设立的?&#xff08;&#xff09; A.1962B.1966 C.1976D.1986 孙健代表的实验室的前身主要研究什么?&…...

初级java每日一道面试题-2024年7月23日-Iterator和ListIterator有什么区别?

面试官: Iterator和ListIterator有什么区别? 我回答: Iterator和ListIterator都是Java集合框架中用于遍历集合元素的接口&#xff0c;但它们之间存在一些关键的区别&#xff0c;主要体现在功能和使用场景上。下面我将详细解释这两种迭代器的不同之处&#xff1a; 1. Iterat…...

2024-07-23 Unity AI行为树2 —— 项目介绍

文章目录 1 项目介绍2 AI 代码介绍2.1 BTBaseNode / BTControlNode2.2 动作/条件节点2.3 选择 / 顺序节点 3 怪物实现4 其他功能5 UML 类图 项目借鉴 B 站唐老狮 2023年直播内容。 点击前往唐老狮 B 站主页。 1 项目介绍 ​ 本项目使用 Unity 2022.3.32f1c1&#xff0c;实现基…...

Unity-URP-SSAO记录

勾选After Opacity Unity-URP管线&#xff0c;本来又一个“bug”, 网上查不到很多关于ssao的资料 以为会不会又是一个极度少人用的东西 而且几乎都是要第三方替代 也完全没有SSAO大概的消耗是多少&#xff0c;完全是黑盒(因为用的人少&#xff0c;研究的人少&#xff0c;优…...

无人机上磁航技术详解

磁航技术&#xff0c;也被称为地磁导航&#xff0c;是一种利用地球磁场信息来实现导航的技术。在无人机领域&#xff0c;磁航技术主要用于辅助惯性导航系统&#xff08;INS&#xff09;进行航向角的测量与校正&#xff0c;提高无人机的飞行稳定性和准确性。其技术原理是&#x…...

使用 cURL 命令测试网站响应时间

文章目录 使用 cURL 命令测试网站响应时间工具介绍cURL 命令详解命令参数说明输出格式说明示例运行结果总结使用 cURL 命令测试网站响应时间 本文将介绍如何使用 cURL 命令行工具来测试一个网站的响应时间。具体来说,我们将使用 cURL 命令来测量并显示各种网络性能指标,包括 …...

「网络通信」HTTP 协议

HTTP &#x1f349;简介&#x1f349;抓包工具&#x1f349;报文结构&#x1f34c;请求&#x1f34c;响应&#x1f34c;URL&#x1f95d;URL encode &#x1f34c;方法&#x1f34c;报文字段&#x1f95d;Host&#x1f95d;Content-Length & Content-Type&#x1f95d;User…...

科普文:后端性能优化的实战小结

一、背景与效果 ICBU的核心沟通场景有了10年的“积累”&#xff0c;核心场景的界面响应耗时被拉的越来越长&#xff0c;也让性能优化工作提上了日程&#xff0c;先说结论&#xff0c;经过这一波前后端齐心协力的优化努力&#xff0c;两个核心界面90分位的数据&#xff0c;FCP平…...

LeetCode-day23-3098. 求出所有子序列的能量和

LeetCode-day23-3098. 求出所有子序列的能量和 题目描述示例示例1&#xff1a;示例2&#xff1a;示例3&#xff1a; 思路代码 题目描述 给你一个长度为 n 的整数数组 nums 和一个 正 整数 k 。 一个 子序列的 能量 定义为子序列中 任意 两个元素的差值绝对值的 最小值 。 请…...

CSS3雷达扫描效果

CSS3雷达扫描效果https://www.bootstrapmb.com/item/14840 要创建一个CSS3的雷达扫描效果&#xff0c;我们可以使用CSS的动画&#xff08;keyframes&#xff09;和transform属性。以下是一个简单的示例&#xff0c;展示了如何创建一个类似雷达扫描的动画效果&#xff1a; HTM…...