Skip to content

Commit 05034db

Browse files
authored
Modernize binary_search_test.cc (#4994)
1 parent 382b12a commit 05034db

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

ortools/algorithms/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ cc_test(
3636
deps = [
3737
":binary_search",
3838
"//ortools/base:gmock_main",
39-
"//ortools/base:murmur",
4039
"@abseil-cpp//absl/base:log_severity",
40+
"@abseil-cpp//absl/hash",
4141
"@abseil-cpp//absl/numeric:int128",
4242
"@abseil-cpp//absl/random",
4343
"@abseil-cpp//absl/random:distributions",
4444
"@abseil-cpp//absl/strings:str_format",
45+
"@abseil-cpp//absl/strings:string_view",
4546
"@abseil-cpp//absl/time",
4647
"@google_benchmark//:benchmark",
4748
],

ortools/algorithms/binary_search_test.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@
2222
#include <vector>
2323

2424
#include "absl/base/log_severity.h"
25+
#include "absl/hash/hash.h"
2526
#include "absl/numeric/int128.h"
2627
#include "absl/random/distributions.h"
2728
#include "absl/random/random.h"
2829
#include "absl/strings/str_format.h"
30+
#include "absl/strings/string_view.h"
2931
#include "absl/time/clock.h"
3032
#include "absl/time/time.h"
3133
#include "benchmark/benchmark.h"
3234
#include "gtest/gtest.h"
3335
#include "ortools/base/gmock.h"
34-
#include "ortools/base/hash.h"
3536

3637
namespace operations_research {
3738

@@ -259,12 +260,8 @@ TEST(BinarySearchTest, NonMonoticPredicateReachesLocalInflexionPoint_Double) {
259260
const int kNumAttempts = 100000;
260261
for (int attempt = 0; attempt < kNumAttempts; ++attempt) {
261262
const uint64_t hash_seed = random();
262-
std::function<bool(double)> non_monotonic_predicate =
263-
[hash_seed](double x) {
264-
return fasthash64(reinterpret_cast<const char*>(&x), sizeof(x),
265-
hash_seed) &
266-
1;
267-
};
263+
const std::function<bool(double)> non_monotonic_predicate =
264+
[hash_seed](double x) { return absl::HashOf(x, hash_seed) & 1; };
268265
// Pick a random [x_true, x_false] interval which verifies f(x_true) = true
269266
// and f(x_false) = false.
270267
double x_true, x_false;

0 commit comments

Comments
 (0)