catch-unit-test

How to use floating point tolerances in the Catch framework?

China☆狼群 提交于 2019-12-03 10:45:35
问题 I'm using the Catch test framework. In the introductory blog post the author mentions the following feature: Floating point tolerances supported in an easy to use way I couldn't find any documentation on how to do this. How is this done in Catch? 回答1: It's simple. There is a class called Approx that lets you do this test in a very readable manner: #include <limits> TEST_CASE("demo/approx", "Approx demo") { double a = 1.0; double b = a + std::numeric_limits<double>::epsilon(); REQUIRE_FALSE(b

Catch lib (unit testing) and CTest (CMake) integration

ぃ、小莉子 提交于 2019-12-03 04:19:18
问题 I'm looking for successful example of Catch CatchLib integration with CMake test (Ctest) . as I understand this is additional cmake script which has to parse application ouput? Did someone already written this? probably shared this? ================================================== update (solution has been found) : I've committed cmake script to CatchLib , for the integration Catch with CTest. this is a simplified version of Fraser99's cmake script here 回答1: Integrating Catch with CMake is

How to use floating point tolerances in the Catch framework?

十年热恋 提交于 2019-12-03 01:12:57
I'm using the Catch test framework. In the introductory blog post the author mentions the following feature: Floating point tolerances supported in an easy to use way I couldn't find any documentation on how to do this. How is this done in Catch? It's simple. There is a class called Approx that lets you do this test in a very readable manner: #include <limits> TEST_CASE("demo/approx", "Approx demo") { double a = 1.0; double b = a + std::numeric_limits<double>::epsilon(); REQUIRE_FALSE(b == a); REQUIRE(b == Approx(a)); } The tolerance can be changed by using the member functions epsilon() and

Catch lib (unit testing) and CTest (CMake) integration

醉酒当歌 提交于 2019-12-02 17:36:24
I'm looking for successful example of Catch CatchLib integration with CMake test (Ctest) . as I understand this is additional cmake script which has to parse application ouput? Did someone already written this? probably shared this? ================================================== update (solution has been found) : I've committed cmake script to CatchLib , for the integration Catch with CTest. this is a simplified version of Fraser99's cmake script here Integrating Catch with CMake is rather simple, as it's a header-only library. Here's a quick rundown of what you have to do: You can either

How to use CMake with Catch2?

白昼怎懂夜的黑 提交于 2019-11-29 10:57:48
From Catch2's example , I tried to run this example with cmake where structure of my project is like this: /factorial +-- CMakeLists.txt +-- /bin +-- /include | +-- catch.hpp | +-- fact.hpp +-- /src | +-- CMakeLists.txt | +-- fact.cpp +-- /test +-- CMakeLists.txt +-- test_fact.cpp fact.cpp : unsigned int factorial( unsigned int number ) { return number <= 1 ? number : factorial(number-1)*number; } fact.hpp : #ifndef FACT_H #define FACT_H unsigned int factorial(unsigned int); #endif test_fact.cpp : #define CATCH_CONFIG_MAIN #include "catch.hpp" #include "fact.hpp" TEST_CASE( "factorials are