diff options
author | vmpstr@chromium.org <vmpstr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-25 22:50:26 +0000 |
---|---|---|
committer | vmpstr@chromium.org <vmpstr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-25 22:50:26 +0000 |
commit | b8297c7b867e1b08ab05f4b7864ce84358e64e85 (patch) | |
tree | d89a1cacefc4ba842f874b5a5bba5fe71a0d14b7 /cc/base/util_unittest.cc | |
parent | b72418f894085aafc74a39650c607ce687e1eeb2 (diff) | |
download | chromium_src-b8297c7b867e1b08ab05f4b7864ce84358e64e85.zip chromium_src-b8297c7b867e1b08ab05f4b7864ce84358e64e85.tar.gz chromium_src-b8297c7b867e1b08ab05f4b7864ce84358e64e85.tar.bz2 |
cc: RoundUp/RoundDown unittests.
This adds unittests to RoundUp/RoundDown, and reorders the
cc_tests.gyp files to be in alphabetical order.
Review URL: https://chromiumcodereview.appspot.com/13896025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196517 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/base/util_unittest.cc')
-rw-r--r-- | cc/base/util_unittest.cc | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/cc/base/util_unittest.cc b/cc/base/util_unittest.cc new file mode 100644 index 0000000..6665a6a --- /dev/null +++ b/cc/base/util_unittest.cc @@ -0,0 +1,67 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "cc/base/util.h" + +#include "testing/gtest/include/gtest/gtest.h" + +namespace cc { +namespace { + +TEST(UtilTest, RoundUp) { + for (int multiplier = 1; multiplier <= 10; ++multiplier) { + // Try attempts in descending order, so that we can + // determine the correct value before it's needed. + int correct; + for (int attempt = 5 * multiplier; attempt >= -5 * multiplier; --attempt) { + if ((attempt % multiplier) == 0) + correct = attempt; + EXPECT_EQ(correct, RoundUp(attempt, multiplier)) + << "attempt=" << attempt << " multiplier=" << multiplier; + } + } + + for (unsigned multiplier = 1; multiplier <= 10; ++multiplier) { + // Try attempts in descending order, so that we can + // determine the correct value before it's needed. + unsigned correct; + for (unsigned attempt = 5 * multiplier; attempt > 0; --attempt) { + if ((attempt % multiplier) == 0) + correct = attempt; + EXPECT_EQ(correct, RoundUp(attempt, multiplier)) + << "attempt=" << attempt << " multiplier=" << multiplier; + } + EXPECT_EQ(0u, RoundUp(0u, multiplier)) + << "attempt=0 multiplier=" << multiplier; + } +} + +TEST(UtilTest, RoundDown) { + for (int multiplier = 1; multiplier <= 10; ++multiplier) { + // Try attempts in ascending order, so that we can + // determine the correct value before it's needed. + int correct; + for (int attempt = -5 * multiplier; attempt <= 5 * multiplier; ++attempt) { + if ((attempt % multiplier) == 0) + correct = attempt; + EXPECT_EQ(correct, RoundDown(attempt, multiplier)) + << "attempt=" << attempt << " multiplier=" << multiplier; + } + } + + for (unsigned multiplier = 1; multiplier <= 10; ++multiplier) { + // Try attempts in ascending order, so that we can + // determine the correct value before it's needed. + unsigned correct; + for (unsigned attempt = 0; attempt <= 5 * multiplier; ++attempt) { + if ((attempt % multiplier) == 0) + correct = attempt; + EXPECT_EQ(correct, RoundDown(attempt, multiplier)) + << "attempt=" << attempt << " multiplier=" << multiplier; + } + } +} + +} // namespace +} // namespace cc |