Macros
duration_test.cc File Reference
#include <chrono>
#include <cmath>
#include <cstdint>
#include <ctime>
#include <iomanip>
#include <limits>
#include <random>
#include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/time.h"
Include dependency graph for duration_test.cc:

Go to the source code of this file.

Macros

#define ROUND_TRIP_UNIT(U, LOW, HIGH)
 
#define TEST_ADD_OPS(UNIT)
 
#define TEST_DURATION_CONVERSION(UNIT)
 
#define TEST_FACTORY_OVERLOADS(NAME)
 
#define TEST_INF_DIV_WITH_TYPE(T)
 
#define TEST_INF_MUL_WITH_TYPE(T)
 
#define TEST_MOD_IDENTITY(a, b)   EXPECT_EQ((a), ((a) / (b))*(b) + ((a)%(b)))
 
#define TEST_MUL_OPS(UNIT)
 
#define TEST_NAN_HANDLING(NAME, NAN)
 
#define TEST_PARSE_ROUNDTRIP(d)
 
#define TEST_REL_OPS(UNIT)
 

Macro Definition Documentation

#define ROUND_TRIP_UNIT (   U,
  LOW,
  HIGH 
)
Value:
do { \
for (int64_t i = LOW; i < HIGH; ++i) { \
absl::Duration d = absl::U(i); \
if (d == absl::InfiniteDuration()) \
EXPECT_EQ(kint64max, d / absl::U(1)); \
else if (d == -absl::InfiniteDuration()) \
EXPECT_EQ(kint64min, d / absl::U(1)); \
else \
EXPECT_EQ(i, absl::U(i) / absl::U(1)); \
} \
} while (0)
constexpr Duration InfiniteDuration()
Definition: time.h:1513
#define TEST_ADD_OPS (   UNIT)
Value:
do { \
EXPECT_EQ(UNIT(2), UNIT(1) + UNIT(1)); \
EXPECT_EQ(UNIT(1), UNIT(2) - UNIT(1)); \
EXPECT_EQ(UNIT(0), UNIT(2) - UNIT(2)); \
EXPECT_EQ(UNIT(-1), UNIT(1) - UNIT(2)); \
EXPECT_EQ(UNIT(-2), UNIT(0) - UNIT(2)); \
EXPECT_EQ(UNIT(-2), UNIT(1) - UNIT(3)); \
absl::Duration a = UNIT(1); \
a += UNIT(1); \
EXPECT_EQ(UNIT(2), a); \
a -= UNIT(1); \
EXPECT_EQ(UNIT(1), a); \
} while (0)
#define TEST_DURATION_CONVERSION (   UNIT)
Value:
do { \
const absl::Duration d = absl::UNIT(1.5); \
constexpr double dbl_inf = std::numeric_limits<double>::infinity(); \
EXPECT_EQ(kint64min, absl::ToInt64##UNIT(-inf)); \
EXPECT_EQ(-1, absl::ToInt64##UNIT(-d)); \
EXPECT_EQ(0, absl::ToInt64##UNIT(z)); \
EXPECT_EQ(1, absl::ToInt64##UNIT(d)); \
EXPECT_EQ(kint64max, absl::ToInt64##UNIT(inf)); \
EXPECT_EQ(-dbl_inf, absl::ToDouble##UNIT(-inf)); \
EXPECT_EQ(-1.5, absl::ToDouble##UNIT(-d)); \
EXPECT_EQ(0, absl::ToDouble##UNIT(z)); \
EXPECT_EQ(1.5, absl::ToDouble##UNIT(d)); \
EXPECT_EQ(dbl_inf, absl::ToDouble##UNIT(inf)); \
} while (0)
int64_t ToInt64(Duration d, Ratio)
Definition: time.h:1411
constexpr Duration InfiniteDuration()
Definition: time.h:1513
constexpr Duration ZeroDuration()
Definition: time.h:286
#define TEST_FACTORY_OVERLOADS (   NAME)
Value:
EXPECT_EQ(1, NAME(kOne) / NAME(kOne)); \
EXPECT_EQ(1, NAME(static_cast<int8_t>(1)) / NAME(1)); \
EXPECT_EQ(1, NAME(static_cast<int16_t>(1)) / NAME(1)); \
EXPECT_EQ(1, NAME(static_cast<int32_t>(1)) / NAME(1)); \
EXPECT_EQ(1, NAME(static_cast<int64_t>(1)) / NAME(1)); \
EXPECT_EQ(1, NAME(static_cast<uint8_t>(1)) / NAME(1)); \
EXPECT_EQ(1, NAME(static_cast<uint16_t>(1)) / NAME(1)); \
EXPECT_EQ(1, NAME(static_cast<uint32_t>(1)) / NAME(1)); \
EXPECT_EQ(1, NAME(static_cast<uint64_t>(1)) / NAME(1)); \
EXPECT_EQ(NAME(1) / 2, NAME(static_cast<float>(0.5))); \
EXPECT_EQ(NAME(1) / 2, NAME(static_cast<double>(0.5))); \
EXPECT_EQ(1.5, absl::FDivDuration(NAME(static_cast<float>(1.5)), NAME(1))); \
EXPECT_EQ(1.5, absl::FDivDuration(NAME(static_cast<double>(1.5)), NAME(1)));
double FDivDuration(Duration num, Duration den)
Definition: duration.cc:476
#define TEST_INF_DIV_WITH_TYPE (   T)
Value:
EXPECT_EQ(inf, inf / static_cast<T>(2)); \
EXPECT_EQ(-inf, inf / static_cast<T>(-2)); \
EXPECT_EQ(-inf, -inf / static_cast<T>(2)); \
EXPECT_EQ(inf, -inf / static_cast<T>(-2));
#define TEST_INF_MUL_WITH_TYPE (   T)
Value:
EXPECT_EQ(inf, inf * static_cast<T>(2)); \
EXPECT_EQ(-inf, inf * static_cast<T>(-2)); \
EXPECT_EQ(-inf, -inf * static_cast<T>(2)); \
EXPECT_EQ(inf, -inf * static_cast<T>(-2)); \
EXPECT_EQ(inf, inf * static_cast<T>(0)); \
EXPECT_EQ(-inf, -inf * static_cast<T>(0)); \
EXPECT_EQ(inf, sec_max * static_cast<T>(2)); \
EXPECT_EQ(inf, sec_min * static_cast<T>(-2)); \
EXPECT_EQ(inf, (sec_max / static_cast<T>(2)) * static_cast<T>(3)); \
EXPECT_EQ(-inf, sec_max * static_cast<T>(-2)); \
EXPECT_EQ(-inf, sec_min * static_cast<T>(2)); \
EXPECT_EQ(-inf, (sec_min / static_cast<T>(2)) * static_cast<T>(3));
#define TEST_MOD_IDENTITY (   a,
  b 
)    EXPECT_EQ((a), ((a) / (b))*(b) + ((a)%(b)))
#define TEST_MUL_OPS (   UNIT)
Value:
do { \
EXPECT_EQ(UNIT(5), UNIT(2) * 2.5); \
EXPECT_EQ(UNIT(2), UNIT(5) / 2.5); \
EXPECT_EQ(UNIT(-5), UNIT(-2) * 2.5); \
EXPECT_EQ(UNIT(-5), -UNIT(2) * 2.5); \
EXPECT_EQ(UNIT(-5), UNIT(2) * -2.5); \
EXPECT_EQ(UNIT(-2), UNIT(-5) / 2.5); \
EXPECT_EQ(UNIT(-2), -UNIT(5) / 2.5); \
EXPECT_EQ(UNIT(-2), UNIT(5) / -2.5); \
EXPECT_EQ(UNIT(2), UNIT(11) % UNIT(3)); \
absl::Duration a = UNIT(2); \
a *= 2.5; \
EXPECT_EQ(UNIT(5), a); \
a /= 2.5; \
EXPECT_EQ(UNIT(2), a); \
a %= UNIT(1); \
EXPECT_EQ(UNIT(0), a); \
absl::Duration big = UNIT(1000000000); \
big *= 3; \
big /= 3; \
EXPECT_EQ(UNIT(1000000000), big); \
EXPECT_EQ(-UNIT(2), -UNIT(2)); \
EXPECT_EQ(-UNIT(2), UNIT(2) * -1); \
EXPECT_EQ(-UNIT(2), -1 * UNIT(2)); \
EXPECT_EQ(-UNIT(-2), UNIT(2)); \
EXPECT_EQ(2, UNIT(2) / UNIT(1)); \
absl::Duration rem; \
EXPECT_EQ(2, absl::IDivDuration(UNIT(2), UNIT(1), &rem)); \
EXPECT_EQ(2.0, absl::FDivDuration(UNIT(2), UNIT(1))); \
} while (0)
int64_t IDivDuration(Duration num, Duration den, Duration *rem)
Definition: time.h:263
double FDivDuration(Duration num, Duration den)
Definition: duration.cc:476
#define TEST_NAN_HANDLING (   NAME,
  NAN 
)
Value:
do { \
const auto inf = absl::InfiniteDuration(); \
auto x = NAME(NAN); \
EXPECT_TRUE(x == inf || x == -inf); \
auto y = NAME(42); \
y *= NAN; \
EXPECT_TRUE(y == inf || y == -inf); \
auto z = NAME(42); \
z /= NAN; \
EXPECT_TRUE(z == inf || z == -inf); \
} while (0)
constexpr Duration InfiniteDuration()
Definition: time.h:1513
#define TEST_PARSE_ROUNDTRIP (   d)
Value:
do { \
std::string s = absl::FormatDuration(d); \
absl::Duration dur; \
EXPECT_TRUE(absl::ParseDuration(s, &dur)); \
EXPECT_EQ(d, dur); \
} while (0)
std::string FormatDuration(Duration d)
Definition: duration.cc:758
bool ParseDuration(const std::string &dur_string, Duration *d)
Definition: duration.cc:863
#define TEST_REL_OPS (   UNIT)
Value:
static_assert(UNIT(2) == UNIT(2), ""); \
static_assert(UNIT(1) != UNIT(2), ""); \
static_assert(UNIT(1) < UNIT(2), ""); \
static_assert(UNIT(3) > UNIT(2), ""); \
static_assert(UNIT(1) <= UNIT(2), ""); \
static_assert(UNIT(2) <= UNIT(2), ""); \
static_assert(UNIT(3) >= UNIT(2), ""); \
static_assert(UNIT(2) >= UNIT(2), "");


abseil_cpp
Author(s):
autogenerated on Tue Jun 18 2019 19:44:38