Skip to content

Commit eee09fd

Browse files
authored
test: make freelancer rates more robust (#936)
[no important files changed]
1 parent a3b9016 commit eee09fd

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

exercises/concept/freelancer-rates/freelancer_rates_test.cpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,33 @@
55
#include "test/catch.hpp"
66
#endif
77

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+
812
using namespace std;
913

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+
}
1117

1218
#if defined(EXERCISM_RUN_ALL_TESTS)
1319

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+
}
1523

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+
}
1727

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));
2032
}
2133

2234
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
2535
REQUIRE_THAT(apply_discount(111.11, 13.5),
2636
Catch::Matchers::WithinRel(96.11015, 0.000001));
2737
}

0 commit comments

Comments
 (0)