diff options
author | michaeln <michaeln@chromium.org> | 2015-02-23 13:22:42 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-23 21:23:58 +0000 |
commit | 6e3b48b35f7a96246bcc0bb9e2ec846053349d99 (patch) | |
tree | cb19145681aa6cdffc68f336572e18cb41c6d5e7 /base/time/time_unittest.cc | |
parent | 2289630132c8e3ff98ea978371527bea3966ce4c (diff) | |
download | chromium_src-6e3b48b35f7a96246bcc0bb9e2ec846053349d99.zip chromium_src-6e3b48b35f7a96246bcc0bb9e2ec846053349d99.tar.gz chromium_src-6e3b48b35f7a96246bcc0bb9e2ec846053349d99.tar.bz2 |
base::Time multiplicative operator overloading
Review URL: https://codereview.chromium.org/945143002
Cr-Commit-Position: refs/heads/master@{#317653}
Diffstat (limited to 'base/time/time_unittest.cc')
-rw-r--r-- | base/time/time_unittest.cc | 72 |
1 files changed, 69 insertions, 3 deletions
diff --git a/base/time/time_unittest.cc b/base/time/time_unittest.cc index 6387ec7..a96787c 100644 --- a/base/time/time_unittest.cc +++ b/base/time/time_unittest.cc @@ -868,12 +868,78 @@ TEST(TimeDelta, Magnitude) { } -TEST(TimeDelta, multiply_by) { +TEST(TimeDelta, NumericOperators) { double d = 0.5; EXPECT_EQ(TimeDelta::FromMilliseconds(500), - TimeDelta::FromMilliseconds(1000).multiply_by(d)); + TimeDelta::FromMilliseconds(1000) * d); EXPECT_EQ(TimeDelta::FromMilliseconds(2000), - TimeDelta::FromMilliseconds(1000).divide_by(d)); + TimeDelta::FromMilliseconds(1000) / d); + EXPECT_EQ(TimeDelta::FromMilliseconds(500), + TimeDelta::FromMilliseconds(1000) *= d); + EXPECT_EQ(TimeDelta::FromMilliseconds(2000), + TimeDelta::FromMilliseconds(1000) /= d); + EXPECT_EQ(TimeDelta::FromMilliseconds(500), + d * TimeDelta::FromMilliseconds(1000)); + + float f = 0.5; + EXPECT_EQ(TimeDelta::FromMilliseconds(500), + TimeDelta::FromMilliseconds(1000) * f); + EXPECT_EQ(TimeDelta::FromMilliseconds(2000), + TimeDelta::FromMilliseconds(1000) / f); + EXPECT_EQ(TimeDelta::FromMilliseconds(500), + TimeDelta::FromMilliseconds(1000) *= f); + EXPECT_EQ(TimeDelta::FromMilliseconds(2000), + TimeDelta::FromMilliseconds(1000) /= f); + EXPECT_EQ(TimeDelta::FromMilliseconds(500), + f * TimeDelta::FromMilliseconds(1000)); + + + int i = 2; + EXPECT_EQ(TimeDelta::FromMilliseconds(2000), + TimeDelta::FromMilliseconds(1000) * i); + EXPECT_EQ(TimeDelta::FromMilliseconds(500), + TimeDelta::FromMilliseconds(1000) / i); + EXPECT_EQ(TimeDelta::FromMilliseconds(2000), + TimeDelta::FromMilliseconds(1000) *= i); + EXPECT_EQ(TimeDelta::FromMilliseconds(500), + TimeDelta::FromMilliseconds(1000) /= i); + EXPECT_EQ(TimeDelta::FromMilliseconds(2000), + i * TimeDelta::FromMilliseconds(1000)); + + int64_t i64 = 2; + EXPECT_EQ(TimeDelta::FromMilliseconds(2000), + TimeDelta::FromMilliseconds(1000) * i64); + EXPECT_EQ(TimeDelta::FromMilliseconds(500), + TimeDelta::FromMilliseconds(1000) / i64); + EXPECT_EQ(TimeDelta::FromMilliseconds(2000), + TimeDelta::FromMilliseconds(1000) *= i64); + EXPECT_EQ(TimeDelta::FromMilliseconds(500), + TimeDelta::FromMilliseconds(1000) /= i64); + EXPECT_EQ(TimeDelta::FromMilliseconds(2000), + i64 * TimeDelta::FromMilliseconds(1000)); + + + EXPECT_EQ(TimeDelta::FromMilliseconds(500), + TimeDelta::FromMilliseconds(1000) * 0.5); + EXPECT_EQ(TimeDelta::FromMilliseconds(2000), + TimeDelta::FromMilliseconds(1000) / 0.5); + EXPECT_EQ(TimeDelta::FromMilliseconds(500), + TimeDelta::FromMilliseconds(1000) *= 0.5); + EXPECT_EQ(TimeDelta::FromMilliseconds(2000), + TimeDelta::FromMilliseconds(1000) /= 0.5); + EXPECT_EQ(TimeDelta::FromMilliseconds(500), + 0.5 * TimeDelta::FromMilliseconds(1000)); + + EXPECT_EQ(TimeDelta::FromMilliseconds(2000), + TimeDelta::FromMilliseconds(1000) * 2); + EXPECT_EQ(TimeDelta::FromMilliseconds(500), + TimeDelta::FromMilliseconds(1000) / 2); + EXPECT_EQ(TimeDelta::FromMilliseconds(2000), + TimeDelta::FromMilliseconds(1000) *= 2); + EXPECT_EQ(TimeDelta::FromMilliseconds(500), + TimeDelta::FromMilliseconds(1000) /= 2); + EXPECT_EQ(TimeDelta::FromMilliseconds(2000), + 2 * TimeDelta::FromMilliseconds(1000)); } TEST(TimeDeltaLogging, DCheckEqCompiles) { |