Chapter 6 Exercise Set 2: Doctest ExercisesΒΆ
We introduced doctest in Chapter 5 Extention: Introducing doctest. Review that section if you are not yet familiar with it.
In each of the following exercises, create a file with the following scaffolding and then modify it according to the given problem:
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <string>
#include <doctest.h>
using namespace std;
// Your function goes here
TEST_CASE("...") {
CHECK(...);
}
Create a file named
test_reverse_string.cppthat takes a string,s, as an argument, and returns a new string which has the charaters fromsin reverse order.TEST_CASE("reverse_string(s) returns s backwards") { CHECK(reverse_string("happy") == "yppah"); CHECK(reverse_string("GHC!") == "!CHG"); CHECK(reverse_string("The end.") == ".dne ehT"); }