This source file includes following definitions.
- TEST
- TEST
#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) {
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) {
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) {
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) {
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;
}
}
}
}
}