Automated Commit: Committing new LKGM version 6953.0.0 for chromeos.
[chromium-blink-merge.git] / cc / base / util_unittest.cc
blob6665a6a458dd6742693187ee2b59784a27fac8fd
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/base/util.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace cc {
10 namespace {
12 TEST(UtilTest, RoundUp) {
13 for (int multiplier = 1; multiplier <= 10; ++multiplier) {
14 // Try attempts in descending order, so that we can
15 // determine the correct value before it's needed.
16 int correct;
17 for (int attempt = 5 * multiplier; attempt >= -5 * multiplier; --attempt) {
18 if ((attempt % multiplier) == 0)
19 correct = attempt;
20 EXPECT_EQ(correct, RoundUp(attempt, multiplier))
21 << "attempt=" << attempt << " multiplier=" << multiplier;
25 for (unsigned multiplier = 1; multiplier <= 10; ++multiplier) {
26 // Try attempts in descending order, so that we can
27 // determine the correct value before it's needed.
28 unsigned correct;
29 for (unsigned attempt = 5 * multiplier; attempt > 0; --attempt) {
30 if ((attempt % multiplier) == 0)
31 correct = attempt;
32 EXPECT_EQ(correct, RoundUp(attempt, multiplier))
33 << "attempt=" << attempt << " multiplier=" << multiplier;
35 EXPECT_EQ(0u, RoundUp(0u, multiplier))
36 << "attempt=0 multiplier=" << multiplier;
40 TEST(UtilTest, RoundDown) {
41 for (int multiplier = 1; multiplier <= 10; ++multiplier) {
42 // Try attempts in ascending order, so that we can
43 // determine the correct value before it's needed.
44 int correct;
45 for (int attempt = -5 * multiplier; attempt <= 5 * multiplier; ++attempt) {
46 if ((attempt % multiplier) == 0)
47 correct = attempt;
48 EXPECT_EQ(correct, RoundDown(attempt, multiplier))
49 << "attempt=" << attempt << " multiplier=" << multiplier;
53 for (unsigned multiplier = 1; multiplier <= 10; ++multiplier) {
54 // Try attempts in ascending order, so that we can
55 // determine the correct value before it's needed.
56 unsigned correct;
57 for (unsigned attempt = 0; attempt <= 5 * multiplier; ++attempt) {
58 if ((attempt % multiplier) == 0)
59 correct = attempt;
60 EXPECT_EQ(correct, RoundDown(attempt, multiplier))
61 << "attempt=" << attempt << " multiplier=" << multiplier;
66 } // namespace
67 } // namespace cc