| 32 | |
| 33 | template <typename IntegralType, typename TestDataType> |
| 34 | void TestCeilOfRatio(const TestDataType test_data[][kNumTestArguments], |
| 35 | int num_tests) { |
| 36 | for (int i = 0; i < num_tests; ++i) { |
| 37 | const IntegralType numerator = test_data[i][0]; |
| 38 | const IntegralType denominator = test_data[i][1]; |
| 39 | const IntegralType expected_floor = test_data[i][2]; |
| 40 | const IntegralType expected_ceil = test_data[i][3]; |
| 41 | // Make sure the two ways to compute the floor return the same thing. |
| 42 | IntegralType floor_1 = MathUtil::FloorOfRatio(numerator, denominator); |
| 43 | IntegralType floor_2 = MathUtil::CeilOrFloorOfRatio<IntegralType, false>( |
| 44 | numerator, denominator); |
| 45 | EXPECT_EQ(floor_1, floor_2); |
| 46 | EXPECT_EQ(expected_floor, floor_1) |
| 47 | << "FloorOfRatio fails with numerator = " << numerator |
| 48 | << ", denominator = " << denominator << " " |
| 49 | << (8 * sizeof(IntegralType)) << " bits"; |
| 50 | IntegralType ceil_1 = MathUtil::CeilOfRatio(numerator, denominator); |
| 51 | IntegralType ceil_2 = MathUtil::CeilOrFloorOfRatio<IntegralType, true>( |
| 52 | numerator, denominator); |
| 53 | EXPECT_EQ(ceil_1, ceil_2); |
| 54 | EXPECT_EQ(expected_ceil, ceil_1) |
| 55 | << "CeilOfRatio fails with numerator = " << numerator |
| 56 | << ", denominator = " << denominator << " " |
| 57 | << (8 * sizeof(IntegralType)) << " bits"; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | template <typename UnsignedIntegralType> |
| 62 | void TestCeilOfRatioUnsigned(uint64 kMax) { |
nothing calls this directly
no test coverage detected