OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/base/math_util.h" | 5 #include "cc/base/math_util.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "cc/test/geometry_test_utils.h" | 9 #include "cc/test/geometry_test_utils.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 } | 377 } |
378 } | 378 } |
379 | 379 |
380 TEST(MathUtilTest, RoundDownUnderflow) { | 380 TEST(MathUtilTest, RoundDownUnderflow) { |
381 // Rounding down -123 by 50 is -150, which underflows int8_t, but fits in | 381 // Rounding down -123 by 50 is -150, which underflows int8_t, but fits in |
382 // int16_t. | 382 // int16_t. |
383 EXPECT_FALSE(MathUtil::VerifyRoundDown<int8_t>(-123, 50)); | 383 EXPECT_FALSE(MathUtil::VerifyRoundDown<int8_t>(-123, 50)); |
384 EXPECT_TRUE(MathUtil::VerifyRoundDown<int16_t>(-123, 50)); | 384 EXPECT_TRUE(MathUtil::VerifyRoundDown<int16_t>(-123, 50)); |
385 } | 385 } |
386 | 386 |
| 387 TEST(MathUtilTest, AlmostEqualFloats) { |
| 388 float f1 = 7.33907556533813f; |
| 389 float f2 = 7.33907508850098f; |
| 390 float f3 = MathUtil::RoundToFixedPrecision(f1); |
| 391 float f4 = MathUtil::RoundToFixedPrecision(f2); |
| 392 float f5 = MathUtil::RoundToFixedPrecision(2.33907508850098f); |
| 393 |
| 394 EXPECT_TRUE(f1 != f2); |
| 395 EXPECT_TRUE(f3 == f4); |
| 396 EXPECT_FALSE(f3 == f5); |
| 397 } |
| 398 |
387 } // namespace | 399 } // namespace |
388 } // namespace cc | 400 } // namespace cc |
OLD | NEW |