From ad02a06db448d20ce6819cadf1bb3541febae76d Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sat, 13 May 2023 21:28:40 +0200 Subject: [PATCH] u02/tests: Fix floating point comparison MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I didn’t really understand what WithinRel and WithinAbs do. Now I know that for this use case WithinAbs is the better choice. This also increases the allowed deviance for the average point of all points of a star, because this would now fail for larger values. --- u02/src/tests.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/u02/src/tests.cpp b/u02/src/tests.cpp index f0d205a..cde85bb 100644 --- a/u02/src/tests.cpp +++ b/u02/src/tests.cpp @@ -17,7 +17,7 @@ #include "sweep_line_tool.h" #include "util.h" -using Catch::Matchers::WithinRel; +using Catch::Matchers::WithinAbs; TEST_CASE("Transform Mirror") { // elementary operations @@ -440,7 +440,7 @@ TEST_CASE("Barycentric coordinates (prop: Σ = 1)") { // If all points are on a straight line, the property does not hold if (!(x0 == x1 && x1 == x2) && !(y0 == y1 && y1 == y2)) { - REQUIRE_THAT(b1 + b2 + b3, WithinRel(1.0, 0.01)); + REQUIRE_THAT(b1 + b2 + b3, WithinAbs(1.0, 0.01)); } } @@ -580,8 +580,8 @@ TEST_CASE("Star (prop: average of all points is centre)") { y += point.second; } - REQUIRE_THAT(x / points.size(), WithinRel(x0, 0.1)); - REQUIRE_THAT(y / points.size(), WithinRel(y0, 0.1)); + REQUIRE_THAT(x / points.size(), WithinAbs(x0, 0.5)); + REQUIRE_THAT(y / points.size(), WithinAbs(y0, 0.5)); } // The Haskell implementation of regular_polygon_mod has many more tests,