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"
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.
17 for (int attempt
= 5 * multiplier
; attempt
>= -5 * multiplier
; --attempt
) {
18 if ((attempt
% multiplier
) == 0)
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.
29 for (unsigned attempt
= 5 * multiplier
; attempt
> 0; --attempt
) {
30 if ((attempt
% multiplier
) == 0)
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.
45 for (int attempt
= -5 * multiplier
; attempt
<= 5 * multiplier
; ++attempt
) {
46 if ((attempt
% multiplier
) == 0)
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.
57 for (unsigned attempt
= 0; attempt
<= 5 * multiplier
; ++attempt
) {
58 if ((attempt
% multiplier
) == 0)
60 EXPECT_EQ(correct
, RoundDown(attempt
, multiplier
))
61 << "attempt=" << attempt
<< " multiplier=" << multiplier
;