We will keep the main.cpp, sum_integers.cpp, and sum_integers.hpp unchanged from the previous recipe, but will update the test.cpp:
#include "sum_integers.hpp" // this tells catch to provide a main()// only do this in one cpp file#define CATCH_CONFIG_MAIN#include "catch.hpp"#include <vector>TEST_CASE("Sum of integers for a short vector", "[short]") { auto integers = {1, 2, 3, 4, 5}; REQUIRE(sum_integers(integers) == 15);}TEST_CASE("Sum of integers for a longer vector", "[long]") { std::vector<int> integers; for (int i = 1; i < 1001; ++i) { integers.push_back(i); } REQUIRE(sum_integers(integers) == 500500);}
We also need the catch.hpp header, which we can download from https://github.com/catchorg/Catch2 (we have used version ...