From 7af71a69d18c40c5450aed8140613f17b88e1c53 Mon Sep 17 00:00:00 2001 From: vaeng <34183939+vaeng@users.noreply.github.com> Date: Tue, 28 Jan 2025 15:07:19 +0100 Subject: [PATCH] test: make freelancer rates more robust --- .../freelancer_rates_test.cpp | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/exercises/concept/freelancer-rates/freelancer_rates_test.cpp b/exercises/concept/freelancer-rates/freelancer_rates_test.cpp index 857af4e83..91e03a031 100644 --- a/exercises/concept/freelancer-rates/freelancer_rates_test.cpp +++ b/exercises/concept/freelancer-rates/freelancer_rates_test.cpp @@ -5,23 +5,33 @@ #include "test/catch.hpp" #endif +// About the REQUIRE_THAT macro: +// If unsure about the syntax of this test see: +// https://github.com/catchorg/Catch2/blob/devel/docs/comparing-floating-point-numbers.md#withinrel + using namespace std; -TEST_CASE("it's the hourly_rate times 8", "[task_1]") { REQUIRE(daily_rate(50) == 400.0); } +TEST_CASE("it's the hourly_rate times 8", "[task_1]") { + REQUIRE_THAT(daily_rate(50), Catch::Matchers::WithinRel(400.0, 0.000001)); +} #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("it always returns a float", "[task_1]") { REQUIRE(daily_rate(60) == 480.0); } +TEST_CASE("it always returns a float", "[task_1]") { + REQUIRE_THAT(daily_rate(60), Catch::Matchers::WithinRel(480.0, 0.000001)); +} -TEST_CASE("it does not round", "[task_1]") { REQUIRE(daily_rate(55.1) == 440.8); } +TEST_CASE("it does not round", "[task_1]") { + REQUIRE_THAT(daily_rate(55.1), Catch::Matchers::WithinRel(440.8, 0.000001)); +} -TEST_CASE("a discount of 10 percent leaves 90 percent of the original price", "[task_2]") { - REQUIRE(apply_discount(140.0, 10) == 126.0); +TEST_CASE("a discount of 10 percent leaves 90 percent of the original price", + "[task_2]") { + REQUIRE_THAT(apply_discount(140.0, 10), + Catch::Matchers::WithinRel(126.0, 0.000001)); } TEST_CASE("it doesn't round", "[task_2]") { - // If unsure about the syntax of this test see: - // https://github.com/catchorg/Catch2/blob/devel/docs/comparing-floating-point-numbers.md#withinrel REQUIRE_THAT(apply_discount(111.11, 13.5), Catch::Matchers::WithinRel(96.11015, 0.000001)); }