diff options
author | Abseil Team <absl-team@google.com> | 2023-09-08 10:08:22 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-09-08 10:09:20 -0700 |
commit | 09d29c580a30a463fac58ce8b926d283a07f656d (patch) | |
tree | a96e7c992453a84952722c2bfd232cc116786727 /absl/strings | |
parent | 792e55fc0d373b80e4712a6d01ee1834067ef9bd (diff) |
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
Diffstat (limited to 'absl/strings')
-rw-r--r-- | absl/strings/internal/str_format/convert_test.cc | 13 |
1 files changed, 11 insertions, 2 deletions
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 <stdarg.h> #include <stdio.h> +#include <algorithm> #include <cctype> #include <cmath> #include <limits> @@ -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); |