From 09d29c580a30a463fac58ce8b926d283a07f656d Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 8 Sep 2023 10:08:22 -0700 Subject: Fix strict weak ordering in convert_test.cc It sorts NaNs and the test became flaky. Flakiness arises from the fact that sorting checks randomize and check for 100 elements but we sort here around a thousand PiperOrigin-RevId: 563783036 Change-Id: Id25bcb47483acf9c40be3fd1747c37d046197330 --- absl/strings/internal/str_format/convert_test.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'absl/strings/internal/str_format/convert_test.cc') diff --git a/absl/strings/internal/str_format/convert_test.cc b/absl/strings/internal/str_format/convert_test.cc index 16ff9879..0d534651 100644 --- a/absl/strings/internal/str_format/convert_test.cc +++ b/absl/strings/internal/str_format/convert_test.cc @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -684,7 +685,11 @@ TEST_F(FormatConvertTest, Float) { } // Remove duplicates to speed up the logic below. - std::sort(floats.begin(), floats.end()); + std::sort(floats.begin(), floats.end(), [](const float a, const float b) { + if (std::isnan(a)) return false; + if (std::isnan(b)) return true; + return a < b; + }); floats.erase(std::unique(floats.begin(), floats.end()), floats.end()); TestWithMultipleFormatsHelper(floats, {}); @@ -758,7 +763,11 @@ TEST_F(FormatConvertTest, Double) { } // Remove duplicates to speed up the logic below. - std::sort(doubles.begin(), doubles.end()); + std::sort(doubles.begin(), doubles.end(), [](const double a, const double b) { + if (std::isnan(a)) return false; + if (std::isnan(b)) return true; + return a < b; + }); doubles.erase(std::unique(doubles.begin(), doubles.end()), doubles.end()); TestWithMultipleFormatsHelper(doubles, skip_verify); -- cgit v1.2.3