#pragma once #include "vector2d.hpp" #include // default tolerance value constexpr double tolerance = 1e-9; // Compare two Vector2d component-wise, with tolerance, and assert if difference between expected and obtained value is below tolerance inline ::testing::AssertionResult Vec2Near(const Vector2d &a, const Vector2d &b, double tol = tolerance) { if (std::fabs(a.x - b.x) <= tol && std::fabs(a.y - b.y) <= tol) { return ::testing::AssertionSuccess(); } return ::testing::AssertionFailure() << "expected (" << b.x << ", " << b.y << "), got (" << a.x << ", " << a.y << "), diff (" << (a.x - b.x) << ", " << (a.y - b.y) << ")" << ", exceeds tolerance : " << tol; } #define EXPECT_VEC2_NEAR(actual, expected) EXPECT_TRUE(Vec2Near((actual), (expected))) #define EXPECT_VEC2_NEAR_TOL(actual, expected, tol) EXPECT_TRUE(Vec2Near((actual), (expected), (tol)))