TEST(DurationTest, Nanos) { Duration d = Duration::fromNanos(255); EXPECT_EQ(255, d.toIntegerNanos()); EXPECT_EQ(0, d.toIntegerMicros()); EXPECT_EQ(0, d.toIntegerMillis()); EXPECT_EQ(0, d.toIntegerSeconds()); d = Duration::fromNanos(1e9); EXPECT_EQ(1e9, d.toIntegerNanos()); EXPECT_EQ(1e6, d.toIntegerMicros()); EXPECT_EQ(1e3, d.toIntegerMillis()); EXPECT_EQ(1, d.toIntegerSeconds()); }
TEST(DurationTest, Seconds) { Duration d = Duration::fromSeconds(255); EXPECT_EQ(255000000000, d.toIntegerNanos()); EXPECT_EQ(255000000, d.toIntegerMicros()); EXPECT_EQ(255000, d.toIntegerMillis()); EXPECT_EQ(255, d.toIntegerSeconds()); d = Duration::fromSeconds(1e9); EXPECT_EQ(1e18, d.toIntegerNanos()); EXPECT_EQ(1e15, d.toIntegerMicros()); EXPECT_EQ(1e12, d.toIntegerMillis()); EXPECT_EQ(1e9, d.toIntegerSeconds()); }
TEST(DurationTest, AssignSubtract) { Duration d = Duration::fromSeconds(5); Duration d2 = Duration::fromSeconds(10); d -= d2; EXPECT_EQ(-5, d.toIntegerSeconds()); EXPECT_EQ(10, d2.toIntegerSeconds()); }
TEST(DurationTest, AssignAdd) { Duration d = Duration::fromSeconds(5); Duration d2 = Duration::fromSeconds(2); d += d2; EXPECT_EQ(7, d.toIntegerSeconds()); EXPECT_EQ(2, d2.toIntegerSeconds()); }
TEST(DurationTest, Subtract) { Duration d = Duration::fromSeconds(5); Duration d2 = Duration::fromSeconds(2); Duration d3 = d - d2; EXPECT_EQ(5, d.toIntegerSeconds()); EXPECT_EQ(2, d2.toIntegerSeconds()); EXPECT_EQ(3, d3.toIntegerSeconds()); }
TEST(DurationTest, Add) { Duration d = Duration::fromSeconds(5); Duration d2 = Duration::fromSeconds(2); Duration d3 = d + d2; EXPECT_EQ(5, d.toIntegerSeconds()); EXPECT_EQ(2, d2.toIntegerSeconds()); EXPECT_EQ(7, d3.toIntegerSeconds()); }