OLD | NEW |
---|---|
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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 a.SetToMin(Vector2dF(8.5f, 10.5f)); | 242 a.SetToMin(Vector2dF(8.5f, 10.5f)); |
243 EXPECT_EQ(Vector2dF(8.5f, 10.5f).ToString(), a.ToString()); | 243 EXPECT_EQ(Vector2dF(8.5f, 10.5f).ToString(), a.ToString()); |
244 a.SetToMin(Vector2dF(11.5f, 9.5f)); | 244 a.SetToMin(Vector2dF(11.5f, 9.5f)); |
245 EXPECT_EQ(Vector2dF(8.5f, 9.5f).ToString(), a.ToString()); | 245 EXPECT_EQ(Vector2dF(8.5f, 9.5f).ToString(), a.ToString()); |
246 a.SetToMin(Vector2dF(7.5f, 11.5f)); | 246 a.SetToMin(Vector2dF(7.5f, 11.5f)); |
247 EXPECT_EQ(Vector2dF(7.5f, 9.5f).ToString(), a.ToString()); | 247 EXPECT_EQ(Vector2dF(7.5f, 9.5f).ToString(), a.ToString()); |
248 a.SetToMin(Vector2dF(3.5f, 5.5f)); | 248 a.SetToMin(Vector2dF(3.5f, 5.5f)); |
249 EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString()); | 249 EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString()); |
250 } | 250 } |
251 | 251 |
252 TEST(Vector2dTest, IntegerOverflow) { | |
253 int int_max = std::numeric_limits<int>::max(); | |
254 int int_min = std::numeric_limits<int>::min(); | |
255 | |
256 Vector2d max_vector(int_max, int_max); | |
257 Vector2d min_vector(int_min, int_min); | |
258 Vector2d test; | |
259 | |
260 test = Vector2d(); | |
261 test += Vector2d(int_max, int_max); | |
262 EXPECT_EQ(test, max_vector); | |
263 | |
264 test = Vector2d(); | |
265 test += Vector2d(int_min, int_min); | |
266 EXPECT_EQ(test, min_vector); | |
267 | |
268 test = Vector2d(10, 20); | |
269 test += Vector2d(int_max, int_max); | |
270 EXPECT_EQ(test, max_vector); | |
271 | |
272 test = Vector2d(-10, -20); | |
273 test += Vector2d(int_min, int_min); | |
274 EXPECT_EQ(test, min_vector); | |
275 | |
276 test = Vector2d(); | |
277 test -= Vector2d(int_max, int_max); | |
278 EXPECT_EQ(test, Vector2d(-int_max, -int_max)); | |
279 | |
280 test = Vector2d(); | |
281 test -= Vector2d(int_min, int_min); | |
282 EXPECT_EQ(test, max_vector); | |
283 | |
284 test = Vector2d(10, 20); | |
285 test -= Vector2d(int_min, int_min); | |
286 EXPECT_EQ(test, max_vector); | |
287 | |
288 test = Vector2d(-10, -20); | |
289 test -= Vector2d(int_max, int_max); | |
290 EXPECT_EQ(test, min_vector); | |
291 } | |
252 } // namespace gfx | 292 } // namespace gfx |
danakj
2016/09/21 22:01:36
nit: whitespace below
| |
OLD | NEW |