Home | History | Annotate | Download | only in base
      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.
      4 
      5 #include "cc/base/util.h"
      6 
      7 #include "testing/gtest/include/gtest/gtest.h"
      8 
      9 namespace cc {
     10 namespace {
     11 
     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;
     22     }
     23   }
     24 
     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;
     34     }
     35     EXPECT_EQ(0u, RoundUp(0u, multiplier))
     36         << "attempt=0 multiplier=" << multiplier;
     37   }
     38 }
     39 
     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;
     50     }
     51   }
     52 
     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;
     62     }
     63   }
     64 }
     65 
     66 }  // namespace
     67 }  // namespace cc
     68