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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 if ((attempt % multiplier) == 0) | 240 if ((attempt % multiplier) == 0) |
241 correct = attempt; | 241 correct = attempt; |
242 EXPECT_EQ(correct, MathUtil::UncheckedRoundUp(attempt, multiplier)) | 242 EXPECT_EQ(correct, MathUtil::UncheckedRoundUp(attempt, multiplier)) |
243 << "attempt=" << attempt << " multiplier=" << multiplier; | 243 << "attempt=" << attempt << " multiplier=" << multiplier; |
244 } | 244 } |
245 EXPECT_EQ(0u, MathUtil::UncheckedRoundUp(0u, multiplier)) | 245 EXPECT_EQ(0u, MathUtil::UncheckedRoundUp(0u, multiplier)) |
246 << "attempt=0 multiplier=" << multiplier; | 246 << "attempt=0 multiplier=" << multiplier; |
247 } | 247 } |
248 } | 248 } |
249 | 249 |
250 TEST(MathUtilTest, RoundUpOverFlow) { | 250 TEST(MathUtilTest, RoundUpOverflow) { |
251 // Rounding up 123 by 50 is 150, which overflows int8_t, but fits in uint8_t. | 251 // Rounding up 123 by 50 is 150, which overflows int8_t, but fits in uint8_t. |
252 EXPECT_FALSE(MathUtil::VerifyRoundup<int8_t>(123, 50)); | 252 EXPECT_FALSE(MathUtil::VerifyRoundup<int8_t>(123, 50)); |
253 EXPECT_TRUE(MathUtil::VerifyRoundup<uint8_t>(123, 50)); | 253 EXPECT_TRUE(MathUtil::VerifyRoundup<uint8_t>(123, 50)); |
254 } | 254 } |
255 | 255 |
256 TEST(MathUtilTest, RoundDown) { | 256 TEST(MathUtilTest, RoundDown) { |
257 for (int multiplier = 1; multiplier <= 10; ++multiplier) { | 257 for (int multiplier = 1; multiplier <= 10; ++multiplier) { |
258 // Try attempts in ascending order, so that we can | 258 // Try attempts in ascending order, so that we can |
259 // determine the correct value before it's needed. | 259 // determine the correct value before it's needed. |
260 int correct; | 260 int correct; |
(...skipping 11 matching lines...) Expand all Loading... |
272 unsigned correct; | 272 unsigned correct; |
273 for (unsigned attempt = 0; attempt <= 5 * multiplier; ++attempt) { | 273 for (unsigned attempt = 0; attempt <= 5 * multiplier; ++attempt) { |
274 if ((attempt % multiplier) == 0) | 274 if ((attempt % multiplier) == 0) |
275 correct = attempt; | 275 correct = attempt; |
276 EXPECT_EQ(correct, MathUtil::UncheckedRoundDown(attempt, multiplier)) | 276 EXPECT_EQ(correct, MathUtil::UncheckedRoundDown(attempt, multiplier)) |
277 << "attempt=" << attempt << " multiplier=" << multiplier; | 277 << "attempt=" << attempt << " multiplier=" << multiplier; |
278 } | 278 } |
279 } | 279 } |
280 } | 280 } |
281 | 281 |
282 TEST(MathUtilTest, RoundDownUnderFlow) { | 282 TEST(MathUtilTest, RoundDownUnderflow) { |
283 // Rounding down -123 by 50 is -150, which underflows int8_t, but fits in | 283 // Rounding down -123 by 50 is -150, which underflows int8_t, but fits in |
284 // int16_t. | 284 // int16_t. |
285 EXPECT_FALSE(MathUtil::VerifyRoundDown<int8_t>(-123, 50)); | 285 EXPECT_FALSE(MathUtil::VerifyRoundDown<int8_t>(-123, 50)); |
286 EXPECT_TRUE(MathUtil::VerifyRoundDown<int16_t>(-123, 50)); | 286 EXPECT_TRUE(MathUtil::VerifyRoundDown<int16_t>(-123, 50)); |
287 } | 287 } |
288 | 288 |
289 } // namespace | 289 } // namespace |
290 } // namespace cc | 290 } // namespace cc |
OLD | NEW |