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

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

Issue 636953002: [turbofan] Fix HashCode/Equals for floating point operators. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address offline comments. 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/compiler/common-operator.cc ('k') | test/unittests/compiler/common-operator-unittest.cc » ('j') | 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 90 }
91 std::set<size_t> hs; 91 std::set<size_t> hs;
92 for (const auto& v : vs) { 92 for (const auto& v : vs) {
93 hash<TypeParam> h; 93 hash<TypeParam> h;
94 hs.insert(h(v)); 94 hs.insert(h(v));
95 } 95 }
96 EXPECT_LE(vs.size() / 4u, hs.size()); 96 EXPECT_LE(vs.size() / 4u, hs.size());
97 } 97 }
98 98
99 99
100 TYPED_TEST(FunctionalTest, HashValueArrayUsesHashRange) {
101 TypeParam values[128];
102 this->rng()->NextBytes(&values, sizeof(values));
103 EXPECT_EQ(hash_range(values, values + arraysize(values)), hash_value(values));
104 }
105
106
107 TYPED_TEST(FunctionalTest, BitEqualTo) {
108 bit_equal_to<TypeParam> pred;
109 for (size_t i = 0; i < 128; ++i) {
110 TypeParam v1, v2;
111 this->rng()->NextBytes(&v1, sizeof(v1));
112 this->rng()->NextBytes(&v2, sizeof(v2));
113 EXPECT_PRED2(pred, v1, v1);
114 EXPECT_PRED2(pred, v2, v2);
115 EXPECT_EQ(memcmp(&v1, &v2, sizeof(TypeParam)) == 0, pred(v1, v2));
116 }
117 }
118
119
120 TYPED_TEST(FunctionalTest, BitEqualToImpliesSameBitHash) {
121 bit_hash<TypeParam> h;
122 bit_equal_to<TypeParam> e;
123 TypeParam values[32];
124 this->rng()->NextBytes(&values, sizeof(values));
125 TRACED_FOREACH(TypeParam, v1, values) {
126 TRACED_FOREACH(TypeParam, v2, values) {
127 if (e(v1, v2)) EXPECT_EQ(h(v1), h(v2));
128 }
129 }
130 }
131
132
100 namespace { 133 namespace {
101 134
102 struct Foo { 135 struct Foo {
103 int x; 136 int x;
104 double y; 137 double y;
105 }; 138 };
106 139
107 140
108 size_t hash_value(Foo const& v) { return hash_combine(v.x, v.y); } 141 size_t hash_value(Foo const& v) { return hash_combine(v.x, v.y); }
109 142
110 } // namespace 143 } // namespace
111 144
112 145
113 TEST(FunctionalTest, HashUsesArgumentDependentLookup) { 146 TEST(FunctionalTest, HashUsesArgumentDependentLookup) {
114 const int kIntValues[] = {std::numeric_limits<int>::min(), -1, 0, 1, 42, 147 const int kIntValues[] = {std::numeric_limits<int>::min(), -1, 0, 1, 42,
115 std::numeric_limits<int>::max()}; 148 std::numeric_limits<int>::max()};
116 const double kDoubleValues[] = { 149 const double kDoubleValues[] = {
117 std::numeric_limits<double>::min(), -1, -0, 0, 1, 150 std::numeric_limits<double>::min(), -1, -0, 0, 1,
118 std::numeric_limits<double>::max()}; 151 std::numeric_limits<double>::max()};
119 TRACED_FOREACH(int, x, kIntValues) { 152 TRACED_FOREACH(int, x, kIntValues) {
120 TRACED_FOREACH(double, y, kDoubleValues) { 153 TRACED_FOREACH(double, y, kDoubleValues) {
121 hash<Foo> h; 154 hash<Foo> h;
122 Foo foo = {x, y}; 155 Foo foo = {x, y};
123 EXPECT_EQ(hash_combine(x, y), h(foo)); 156 EXPECT_EQ(hash_combine(x, y), h(foo));
124 } 157 }
125 } 158 }
126 } 159 }
127 160
161
162 TEST(FunctionalTest, BitEqualToFloat) {
163 bit_equal_to<float> pred;
164 EXPECT_FALSE(pred(0.0f, -0.0f));
165 EXPECT_FALSE(pred(-0.0f, 0.0f));
166 float const qNaN = std::numeric_limits<float>::quiet_NaN();
167 float const sNaN = std::numeric_limits<float>::signaling_NaN();
168 EXPECT_PRED2(pred, qNaN, qNaN);
169 EXPECT_PRED2(pred, sNaN, sNaN);
170 }
171
172
173 TEST(FunctionalTest, BitHashFloatDifferentForZeroAndMinusZero) {
174 bit_hash<float> h;
175 EXPECT_NE(h(0.0f), h(-0.0f));
176 }
177
178
179 TEST(FunctionalTest, BitEqualToDouble) {
180 bit_equal_to<double> pred;
181 EXPECT_FALSE(pred(0.0, -0.0));
182 EXPECT_FALSE(pred(-0.0, 0.0));
183 double const qNaN = std::numeric_limits<double>::quiet_NaN();
184 double const sNaN = std::numeric_limits<double>::signaling_NaN();
185 EXPECT_PRED2(pred, qNaN, qNaN);
186 EXPECT_PRED2(pred, sNaN, sNaN);
187 }
188
189
190 TEST(FunctionalTest, BitHashDoubleDifferentForZeroAndMinusZero) {
191 bit_hash<double> h;
192 EXPECT_NE(h(0.0), h(-0.0));
193 }
194
128 } // namespace base 195 } // namespace base
129 } // namespace v8 196 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/common-operator.cc ('k') | test/unittests/compiler/common-operator-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698