Chapter 7 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.
Create a file named test_struct_functions.cpp 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(...);
}
Using the
Pointstructure introduced in Point objects, Add the following test case for the functiondistance_from_origin(Point)that takes aPoint,p, as an argument, and returns its distance from the origin,(0, 0).TEST_CASE("distance_from_origin(p) returns p's distance from (0, 0) ") { p = Point{3, 4}; CHECK(distance_from_origin(p) == 5.0); }