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

Side by Side Diff: ui/gfx/vector2d_unittest.cc

Issue 11776034: Fix a couple test cases where we should be doing floating point comparisons. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 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 | « no previous file | ui/gfx/vector3d_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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium 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 <cmath>
6 #include <limits>
7
5 #include "base/basictypes.h" 8 #include "base/basictypes.h"
6 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/gfx/vector2d.h" 10 #include "ui/gfx/vector2d.h"
8 #include "ui/gfx/vector2d_f.h" 11 #include "ui/gfx/vector2d_f.h"
9 12
10 #include <cmath>
11 #include <limits>
12
13 namespace gfx { 13 namespace gfx {
14 14
15 TEST(Vector2dTest, ConversionToFloat) { 15 TEST(Vector2dTest, ConversionToFloat) {
16 Vector2d i(3, 4); 16 Vector2d i(3, 4);
17 Vector2dF f = i; 17 Vector2dF f = i;
18 EXPECT_EQ(i, f); 18 EXPECT_EQ(i, f);
19 } 19 }
20 20
21 TEST(Vector2dTest, IsZero) { 21 TEST(Vector2dTest, IsZero) {
22 Vector2d int_zero(0, 0); 22 Vector2d int_zero(0, 0);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 335890352589839028212313231225425134332.38123f }, 183 335890352589839028212313231225425134332.38123f },
184 }; 184 };
185 185
186 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(float_values); ++i) { 186 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(float_values); ++i) {
187 double v0 = float_values[i][0]; 187 double v0 = float_values[i][0];
188 double v1 = float_values[i][1]; 188 double v1 = float_values[i][1];
189 double length_squared = 189 double length_squared =
190 static_cast<double>(v0) * v0 + static_cast<double>(v1) * v1; 190 static_cast<double>(v0) * v0 + static_cast<double>(v1) * v1;
191 double length = std::sqrt(length_squared); 191 double length = std::sqrt(length_squared);
192 Vector2dF vector(v0, v1); 192 Vector2dF vector(v0, v1);
193 EXPECT_EQ(length_squared, vector.LengthSquared()); 193 EXPECT_DOUBLE_EQ(length_squared, vector.LengthSquared());
194 EXPECT_EQ(static_cast<float>(length), vector.Length()); 194 EXPECT_FLOAT_EQ(static_cast<float>(length), vector.Length());
195 } 195 }
196 } 196 }
197 197
198 TEST(Vector2dTest, ClampVector2d) { 198 TEST(Vector2dTest, ClampVector2d) {
199 Vector2d a; 199 Vector2d a;
200 200
201 a = Vector2d(3, 5); 201 a = Vector2d(3, 5);
202 EXPECT_EQ(Vector2d(3, 5).ToString(), a.ToString()); 202 EXPECT_EQ(Vector2d(3, 5).ToString(), a.ToString());
203 a.ClampToMin(Vector2d(2, 4)); 203 a.ClampToMin(Vector2d(2, 4));
204 EXPECT_EQ(Vector2d(3, 5).ToString(), a.ToString()); 204 EXPECT_EQ(Vector2d(3, 5).ToString(), a.ToString());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 EXPECT_EQ(Vector2dF(8.5f, 10.5f).ToString(), a.ToString()); 241 EXPECT_EQ(Vector2dF(8.5f, 10.5f).ToString(), a.ToString());
242 a.ClampToMax(Vector2dF(11.5f, 9.5f)); 242 a.ClampToMax(Vector2dF(11.5f, 9.5f));
243 EXPECT_EQ(Vector2dF(8.5f, 9.5f).ToString(), a.ToString()); 243 EXPECT_EQ(Vector2dF(8.5f, 9.5f).ToString(), a.ToString());
244 a.ClampToMax(Vector2dF(7.5f, 11.5f)); 244 a.ClampToMax(Vector2dF(7.5f, 11.5f));
245 EXPECT_EQ(Vector2dF(7.5f, 9.5f).ToString(), a.ToString()); 245 EXPECT_EQ(Vector2dF(7.5f, 9.5f).ToString(), a.ToString());
246 a.ClampToMax(Vector2dF(3.5f, 5.5f)); 246 a.ClampToMax(Vector2dF(3.5f, 5.5f));
247 EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString()); 247 EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString());
248 } 248 }
249 249
250 } // namespace gfx 250 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/vector3d_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698