Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: test/unittests/base/functional-unittest.cc

Issue 632713002: Don't use identity as hash function for integers. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/base/functional.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
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; 85 const size_t kValues = 128;
86 const size_t kMinHashes = kValues / (sizeof(uint64_t) / sizeof(size_t)); 86 const size_t kMinHashes = kValues / 4;
87 std::set<TypeParam> vs; 87 std::set<TypeParam> vs;
88 while (vs.size() != kValues) { 88 while (vs.size() != kValues) {
89 TypeParam v; 89 TypeParam v;
90 this->rng()->NextBytes(&v, sizeof(v)); 90 this->rng()->NextBytes(&v, sizeof(v));
91 vs.insert(v); 91 vs.insert(v);
92 } 92 }
93 std::set<size_t> hs; 93 std::set<size_t> hs;
94 for (const auto& v : vs) { 94 for (const auto& v : vs) {
95 hash<TypeParam> h; 95 hash<TypeParam> h;
96 hs.insert(h(v)); 96 hs.insert(h(v));
(...skipping 25 matching lines...) Expand all
122 TRACED_FOREACH(double, y, kDoubleValues) { 122 TRACED_FOREACH(double, y, kDoubleValues) {
123 hash<Foo> h; 123 hash<Foo> h;
124 Foo foo = {x, y}; 124 Foo foo = {x, y};
125 EXPECT_EQ(hash_combine(x, y), h(foo)); 125 EXPECT_EQ(hash_combine(x, y), h(foo));
126 } 126 }
127 } 127 }
128 } 128 }
129 129
130 } // namespace base 130 } // namespace base
131 } // namespace v8 131 } // namespace v8
OLDNEW
« no previous file with comments | « src/base/functional.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698