| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/base/functional.h" | 5 #include "src/base/functional.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "test/unittests/test-utils.h" | 10 #include "test/unittests/test-utils.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 hash<TypeParam> h1, h2; | 75 hash<TypeParam> h1, h2; |
| 76 for (int i = 0; i < 128; ++i) { | 76 for (int i = 0; i < 128; ++i) { |
| 77 TypeParam v; | 77 TypeParam v; |
| 78 this->rng()->NextBytes(&v, sizeof(v)); | 78 this->rng()->NextBytes(&v, sizeof(v)); |
| 79 EXPECT_EQ(h1(v), h2(v)); | 79 EXPECT_EQ(h1(v), h2(v)); |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 | 83 |
| 84 TYPED_TEST(FunctionalTest, HashIsOkish) { | 84 TYPED_TEST(FunctionalTest, HashIsOkish) { |
| 85 const size_t kValues = 128; | |
| 86 const size_t kMinHashes = kValues / 4; | |
| 87 std::set<TypeParam> vs; | 85 std::set<TypeParam> vs; |
| 88 while (vs.size() != kValues) { | 86 for (size_t i = 0; i < 128; ++i) { |
| 89 TypeParam v; | 87 TypeParam v; |
| 90 this->rng()->NextBytes(&v, sizeof(v)); | 88 this->rng()->NextBytes(&v, sizeof(v)); |
| 91 vs.insert(v); | 89 vs.insert(v); |
| 92 } | 90 } |
| 93 std::set<size_t> hs; | 91 std::set<size_t> hs; |
| 94 for (const auto& v : vs) { | 92 for (const auto& v : vs) { |
| 95 hash<TypeParam> h; | 93 hash<TypeParam> h; |
| 96 hs.insert(h(v)); | 94 hs.insert(h(v)); |
| 97 } | 95 } |
| 98 EXPECT_LE(kMinHashes, hs.size()); | 96 EXPECT_LE(vs.size() / 4u, hs.size()); |
| 99 } | 97 } |
| 100 | 98 |
| 101 | 99 |
| 102 namespace { | 100 namespace { |
| 103 | 101 |
| 104 struct Foo { | 102 struct Foo { |
| 105 int x; | 103 int x; |
| 106 double y; | 104 double y; |
| 107 }; | 105 }; |
| 108 | 106 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 122 TRACED_FOREACH(double, y, kDoubleValues) { | 120 TRACED_FOREACH(double, y, kDoubleValues) { |
| 123 hash<Foo> h; | 121 hash<Foo> h; |
| 124 Foo foo = {x, y}; | 122 Foo foo = {x, y}; |
| 125 EXPECT_EQ(hash_combine(x, y), h(foo)); | 123 EXPECT_EQ(hash_combine(x, y), h(foo)); |
| 126 } | 124 } |
| 127 } | 125 } |
| 128 } | 126 } |
| 129 | 127 |
| 130 } // namespace base | 128 } // namespace base |
| 131 } // namespace v8 | 129 } // namespace v8 |
| OLD | NEW |