Files
263-0007-00L-Advanced-Syste…/headers/test_helpers.hpp
T
[Quy Anh] «Elliot» Nguyen b86c856e08 Inlining + Reorganization + Roofline
2026-05-19 23:17:44 +02:00

19 lines
886 B
C++

#pragma once
#include "vector2d.hpp"
#include <gtest/gtest.h>
// 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)))