Chromium Code Reviews

Unified Diff: base/time/time_unittest.cc

Issue 235233003: Added support to convert double to timedelta's without loss of data during type conversion from dou… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unit tests Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « base/time/time.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time_unittest.cc
diff --git a/base/time/time_unittest.cc b/base/time/time_unittest.cc
index 7402316c309052d62832652746fe0f769ae9b165..63c3a1ac7718fe1cc5f0912b4af78f8d24a60627 100644
--- a/base/time/time_unittest.cc
+++ b/base/time/time_unittest.cc
@@ -517,6 +517,12 @@ TEST_F(TimeTest, TimeDeltaMaxConversions) {
t = TimeDelta::FromMilliseconds(std::numeric_limits<int64>::max());
EXPECT_TRUE(t.is_max());
+ t = TimeDelta::FromSecondsD(std::numeric_limits<double>::infinity());
+ EXPECT_TRUE(t.is_max());
+
+ t = TimeDelta::FromMillisecondsD(std::numeric_limits<double>::infinity());
+ EXPECT_TRUE(t.is_max());
+
t = TimeDelta::FromMicroseconds(std::numeric_limits<int64>::max());
EXPECT_TRUE(t.is_max());
}
@@ -715,6 +721,10 @@ TEST(TimeDelta, FromAndIn) {
EXPECT_TRUE(TimeDelta::FromSeconds(2) == TimeDelta::FromMilliseconds(2000));
EXPECT_TRUE(TimeDelta::FromMilliseconds(2) ==
TimeDelta::FromMicroseconds(2000));
+ EXPECT_TRUE(TimeDelta::FromSecondsD(2.3) ==
+ TimeDelta::FromMilliseconds(2300));
+ EXPECT_TRUE(TimeDelta::FromMillisecondsD(2.5) ==
+ TimeDelta::FromMicroseconds(2500));
EXPECT_EQ(13, TimeDelta::FromDays(13).InDays());
EXPECT_EQ(13, TimeDelta::FromHours(13).InHours());
EXPECT_EQ(13, TimeDelta::FromMinutes(13).InMinutes());
@@ -722,6 +732,10 @@ TEST(TimeDelta, FromAndIn) {
EXPECT_EQ(13.0, TimeDelta::FromSeconds(13).InSecondsF());
EXPECT_EQ(13, TimeDelta::FromMilliseconds(13).InMilliseconds());
EXPECT_EQ(13.0, TimeDelta::FromMilliseconds(13).InMillisecondsF());
+ EXPECT_EQ(13, TimeDelta::FromSecondsD(13.1).InSeconds());
+ EXPECT_EQ(13.1, TimeDelta::FromSecondsD(13.1).InSecondsF());
+ EXPECT_EQ(13, TimeDelta::FromMillisecondsD(13.3).InMilliseconds());
+ EXPECT_EQ(13.3, TimeDelta::FromMillisecondsD(13.3).InMillisecondsF());
mithro-old 2014/04/22 07:05:12 Technically anything EXPECT_EQ with floating point
EXPECT_EQ(13, TimeDelta::FromMicroseconds(13).InMicroseconds());
}
« no previous file with comments | « base/time/time.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine