Commit 09d29c58 by Abseil Team Committed by Copybara-Service

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
parent 792e55fc
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <algorithm>
#include <cctype> #include <cctype>
#include <cmath> #include <cmath>
#include <limits> #include <limits>
...@@ -684,7 +685,11 @@ TEST_F(FormatConvertTest, Float) { ...@@ -684,7 +685,11 @@ TEST_F(FormatConvertTest, Float) {
} }
// Remove duplicates to speed up the logic below. // 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()); floats.erase(std::unique(floats.begin(), floats.end()), floats.end());
TestWithMultipleFormatsHelper(floats, {}); TestWithMultipleFormatsHelper(floats, {});
...@@ -758,7 +763,11 @@ TEST_F(FormatConvertTest, Double) { ...@@ -758,7 +763,11 @@ TEST_F(FormatConvertTest, Double) {
} }
// Remove duplicates to speed up the logic below. // 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()); doubles.erase(std::unique(doubles.begin(), doubles.end()), doubles.end());
TestWithMultipleFormatsHelper(doubles, skip_verify); TestWithMultipleFormatsHelper(doubles, skip_verify);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment