32 #include <gtest/gtest.h>
57 Duration d1, d2, d3, d4, d5, d6, d7, d8, d9;
59 EXPECT_NO_THROW(d1.
fromSec(-2147483648.0));
60 EXPECT_NO_THROW(d2.
fromSec(-2147483647.999999));
61 EXPECT_NO_THROW(d3.
fromSec(2147483647.0));
62 EXPECT_NO_THROW(d4.
fromSec(2147483647.999999));
65 EXPECT_THROW(d1.
fromSec(2147483648.0), std::runtime_error);
66 EXPECT_THROW(d2.
fromSec(6442450943.0), std::runtime_error);
67 EXPECT_THROW(d3.
fromSec(-2147483648.001), std::runtime_error);
68 EXPECT_THROW(d4.
fromSec(-6442450943.0), std::runtime_error);
69 EXPECT_THROW(d5.
fromSec(std::numeric_limits<double>::infinity()), std::runtime_error);
70 EXPECT_THROW(d6.
fromSec(-std::numeric_limits<double>::infinity()), std::runtime_error);
71 EXPECT_THROW(d7.
fromSec(std::numeric_limits<double>::quiet_NaN()), std::runtime_error);
73 EXPECT_THROW(d8.
fromSec(9223372036854775808.0), std::runtime_error);
74 EXPECT_THROW(d9.
fromSec(-9223372036854775809.0), std::runtime_error);
83 EXPECT_NO_THROW(d1.
fromNSec(-2147483648000000000));
84 EXPECT_NO_THROW(d2.
fromNSec(-2147483647999999999));
85 EXPECT_NO_THROW(d3.
fromNSec(2147483647000000000));
86 EXPECT_NO_THROW(d4.
fromNSec(2147483647999999999));
89 EXPECT_THROW(d1.
fromSec(2147483648000000000), std::runtime_error);
90 EXPECT_THROW(d2.
fromSec(4294967296000000000), std::runtime_error);
91 EXPECT_THROW(d3.
fromSec(-2147483648000000001), std::runtime_error);
92 EXPECT_THROW(d4.
fromSec(-6442450943000000000), std::runtime_error);
101 EXPECT_THROW(d1 + d2, std::runtime_error);
105 EXPECT_THROW(d3 - d4, std::runtime_error);
106 EXPECT_THROW(d4 - d3, std::runtime_error);
111 EXPECT_NO_THROW(d7 = d5 + d6);
112 EXPECT_EQ(-2147483648000000000, d7.
toNSec());
122 EXPECT_NO_THROW(d3 = -d1);
123 EXPECT_EQ(-2147483647000000000, d3.
toNSec());
124 EXPECT_NO_THROW(d3 = -d2);
125 EXPECT_EQ(-2147483647999999999, d3.
toNSec());
128 Duration d5(-2147483648, 999999999);
131 EXPECT_NO_THROW(d7 = -d4);
132 EXPECT_EQ(2147483647000000000, d7.
toNSec());
133 EXPECT_NO_THROW(d7 = -d5);
134 EXPECT_EQ(2147483647000000001, d7.
toNSec());
135 EXPECT_NO_THROW(d7 = -d6);
136 EXPECT_EQ(2147483647999999998, d7.
toNSec());
144 EXPECT_EQ(49, d1.
sec);
145 EXPECT_EQ(0, d1.
nsec);
147 EXPECT_EQ(-49, d2.
sec);
148 EXPECT_EQ(0, d2.
nsec);
151 EXPECT_EQ(49, d3.
sec);
152 EXPECT_EQ(1, d3.
nsec);
154 EXPECT_EQ(-50, d4.
sec);
155 EXPECT_EQ(999999999, d4.
nsec);
158 EXPECT_EQ(49, d5.
sec);
159 EXPECT_EQ(999999999, d5.
nsec);
161 EXPECT_EQ(-50, d6.
sec);
162 EXPECT_EQ(1, d6.
nsec);
165 EXPECT_EQ(50, d7.
sec);
166 EXPECT_EQ(0, d7.
nsec);
168 EXPECT_EQ(-50, d8.
sec);
169 EXPECT_EQ(0, d8.
nsec);
172 int main(
int argc,
char **argv){
173 testing::InitGoogleTest(&argc, argv);
174 return RUN_ALL_TESTS();