This commit is contained in:
Laurent Perron
2024-02-09 10:33:22 -08:00
parent ffb1abd467
commit 8cd1c38d1e
5 changed files with 253 additions and 170 deletions

View File

@@ -367,7 +367,6 @@ cc_library(
cc_test(
name = "test_util_test",
srcs = ["test_util_test.cc"],
defines = ["_USE_MATH_DEFINES"],
deps = [
":gtest_main",
":test_util",

View File

@@ -13,7 +13,6 @@
#include "ortools/pdlp/test_util.h"
#define _USE_MATH_DEFINES // Needed for visual studio for M_PI.
#include <cmath>
#include <deque>
#include <limits>
@@ -37,8 +36,11 @@ using ::testing::Matcher;
using ::testing::Not;
TEST(FloatArrayNearTest, TypicalUse) {
// M_PI is problematic on windows (requires _USE_MATH_DEFINES).
// std::numbers::pi is C++20 (incompatible with OR-Tools).
const double kPi = 3.14159265358979323846;
std::vector<double> test_vector({0.998, -1.414, 3.142});
std::vector<double> reference_vector({1.0, -M_SQRT2, M_PI});
std::vector<double> reference_vector({1.0, -std::sqrt(2), kPi});
EXPECT_THAT(test_vector, FloatArrayNear(reference_vector, 1.0e-2));
EXPECT_THAT(test_vector, Not(FloatArrayNear(reference_vector, 1.0e-4)));
}
@@ -96,7 +98,11 @@ TEST(FloatArrayNearTest, WithIntegerElements) {
}
TEST(FloatArrayEqTest, TypicalUse) {
std::vector<float> reference_vector({1.0e6, -M_SQRT2, M_PI});
// M_PI is problematic on windows (requires _USE_MATH_DEFINES).
// std::numbers::pi is C++20 (incompatible with OR-Tools).
const float kPi = 3.14159265358979323846;
const float kSqrt2 = std::sqrt(2);
std::vector<float> reference_vector({1.0e6, -kSqrt2, kPi});
// Values are within 4 ULPs.
std::vector<float> test_vector({1.0e6 + 0.25, -1.41421323, 3.14159262});
EXPECT_THAT(test_vector, FloatArrayEq(reference_vector));