|
5 | 5 | #include "test/catch.hpp"
|
6 | 6 | #endif
|
7 | 7 |
|
| 8 | +// About the REQUIRE_THAT macro: |
| 9 | +// If unsure about the syntax of this test see: |
| 10 | +// https://github.com/catchorg/Catch2/blob/devel/docs/comparing-floating-point-numbers.md#withinrel |
| 11 | + |
8 | 12 | using namespace std;
|
9 | 13 |
|
10 |
| -TEST_CASE("it's the hourly_rate times 8", "[task_1]") { REQUIRE(daily_rate(50) == 400.0); } |
| 14 | +TEST_CASE("it's the hourly_rate times 8", "[task_1]") { |
| 15 | + REQUIRE_THAT(daily_rate(50), Catch::Matchers::WithinRel(400.0, 0.000001)); |
| 16 | +} |
11 | 17 |
|
12 | 18 | #if defined(EXERCISM_RUN_ALL_TESTS)
|
13 | 19 |
|
14 |
| -TEST_CASE("it always returns a float", "[task_1]") { REQUIRE(daily_rate(60) == 480.0); } |
| 20 | +TEST_CASE("it always returns a float", "[task_1]") { |
| 21 | + REQUIRE_THAT(daily_rate(60), Catch::Matchers::WithinRel(480.0, 0.000001)); |
| 22 | +} |
15 | 23 |
|
16 |
| -TEST_CASE("it does not round", "[task_1]") { REQUIRE(daily_rate(55.1) == 440.8); } |
| 24 | +TEST_CASE("it does not round", "[task_1]") { |
| 25 | + REQUIRE_THAT(daily_rate(55.1), Catch::Matchers::WithinRel(440.8, 0.000001)); |
| 26 | +} |
17 | 27 |
|
18 |
| -TEST_CASE("a discount of 10 percent leaves 90 percent of the original price", "[task_2]") { |
19 |
| - REQUIRE(apply_discount(140.0, 10) == 126.0); |
| 28 | +TEST_CASE("a discount of 10 percent leaves 90 percent of the original price", |
| 29 | + "[task_2]") { |
| 30 | + REQUIRE_THAT(apply_discount(140.0, 10), |
| 31 | + Catch::Matchers::WithinRel(126.0, 0.000001)); |
20 | 32 | }
|
21 | 33 |
|
22 | 34 | TEST_CASE("it doesn't round", "[task_2]") {
|
23 |
| - // If unsure about the syntax of this test see: |
24 |
| - // https://github.com/catchorg/Catch2/blob/devel/docs/comparing-floating-point-numbers.md#withinrel |
25 | 35 | REQUIRE_THAT(apply_discount(111.11, 13.5),
|
26 | 36 | Catch::Matchers::WithinRel(96.11015, 0.000001));
|
27 | 37 | }
|
|
0 commit comments