样例:针对斐波拉契的样本量做基准测试 std::uint64_tFibonacci(std::uint64_tnumber){returnnumber<2?1:Fibonacci(number-1)+Fibonacci(number-2);}TEST_CASE("Fibonacci"){CHECK(Fibonacci(0)==1);// some more asserts..CHECK(Fibonacci(5)==8);// some more asserts..// now let's benchmark:BENCH...
Cloud Studio代码运行 std::uint64_tFibonacci(std::uint64_t number){returnnumber<2?1:Fibonacci(number-1)+Fibonacci(number-2);}TEST_CASE("Fibonacci"){CHECK(Fibonacci(0)==1);// some more asserts..CHECK(Fibonacci(5)==8);// some more asserts..// now let's benchmark:BENCHMARK("Fibonacci...
在TDD实践中,Catch2扮演着至关重要的角色。它不仅提供了丰富的断言宏,如REQUIRE、CHECK等,还支持多种测试组织方式,如TEST_CASE和SECTION,使得开发者能够轻松地按照TDD的原则编写测试用例。例如,当需要为一个新功能编写测试时,可以先定义一个失败的测试用例,然后逐步完善实现代码直至测试通过。这一过程不仅有助于提高代...
(BadDir) BOOST_CHECK_EQUAL(false, f());如果我在命令行中执行command,我会得到一个权限被拒绝的错误。aSystemCall将命令作为子进程执行。当子命令以非零错误退出时,aSystemCall将返回一个错误。它不会抛出。如果我在命令行中运行BadDir测试用例,aSystemCall之后的代码永远不会执行,并且测试失败,输出如下: m...
CHECK(factorial(6) == 720); // 非致命断言 } SECTION("边界条件验证") { REQUIRE(factorial(0) == 1); REQUIRE(factorial(-1) == 1); } } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. ...
CHECK_THAT(lhs, matcher expression) 主要内置Matchers –string matchers:StartsWith, EndsWith, Contains, Equals and Matches –vector matchers:Contains, VectorContains and Equals –floating point matchers:WithinULP and WithinAbs REQUIRE_THAT( str, EndsWith( "as a service", Catch::CaseSensitive::No...
-- The CXX compiler identification is MSVC 19.29.30133.0 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - ...
然而,当我们需要执行一系列的需要check的操作时,就可以见识到section的威力。继续vector的测试用例,我们可能需要验证reverse操作不会减少vector的capacity。像下面一样,很自然的就可以做到这些。 SECTION( "reserving bigger changes capacity but not size" ) { ...
CHECK_THROWS_WITH( expression, string or string matcher ) Expects that an exception is thrown that, when converted to a string, matches the string or string matcher provided (see next section for Matchers). e.g. REQUIRE_THROWS_WITH( openThePodBayDoors(), Contains( "afraid" ) && Contains(...
(base) frank@deepin:~/git/Catch2$ mkdir build (base) frank@deepin:~/git/Catch2$ cd build/ (base) frank@deepin:~/git/Catch2/build$ cmake -DCATCH_BUILD_EXAMPLES=ON ../ -- The CXX compiler identification is GNU 9.2.0 -- Check for working CXX compiler: /usr/local/bin/c++ -- ...