| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/core/quic_time.h" | 5 #include "net/quic/core/quic_time.h" |
| 6 #include "net/quic/test_tools/mock_clock.h" | 6 #include "net/quic/test_tools/mock_clock.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace net { | 9 namespace net { |
| 10 namespace test { | 10 namespace test { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 int i = 2; | 52 int i = 2; |
| 53 EXPECT_EQ(QuicTime::Delta::FromMicroseconds(4000), | 53 EXPECT_EQ(QuicTime::Delta::FromMicroseconds(4000), |
| 54 QuicTime::Delta::FromMilliseconds(2) * i); | 54 QuicTime::Delta::FromMilliseconds(2) * i); |
| 55 EXPECT_EQ(QuicTime::Delta::FromMicroseconds(4000), | 55 EXPECT_EQ(QuicTime::Delta::FromMicroseconds(4000), |
| 56 i * QuicTime::Delta::FromMilliseconds(2)); | 56 i * QuicTime::Delta::FromMilliseconds(2)); |
| 57 double d = 2; | 57 double d = 2; |
| 58 EXPECT_EQ(QuicTime::Delta::FromMicroseconds(4000), | 58 EXPECT_EQ(QuicTime::Delta::FromMicroseconds(4000), |
| 59 QuicTime::Delta::FromMilliseconds(2) * d); | 59 QuicTime::Delta::FromMilliseconds(2) * d); |
| 60 EXPECT_EQ(QuicTime::Delta::FromMicroseconds(4000), | 60 EXPECT_EQ(QuicTime::Delta::FromMicroseconds(4000), |
| 61 d * QuicTime::Delta::FromMilliseconds(2)); | 61 d * QuicTime::Delta::FromMilliseconds(2)); |
| 62 |
| 63 // Ensure we are rounding correctly within a single-bit level of precision. |
| 64 EXPECT_EQ(QuicTime::Delta::FromMicroseconds(5), |
| 65 QuicTime::Delta::FromMicroseconds(9) * 0.5); |
| 66 EXPECT_EQ(QuicTime::Delta::FromMicroseconds(2), |
| 67 QuicTime::Delta::FromMicroseconds(12) * 0.2); |
| 62 } | 68 } |
| 63 | 69 |
| 64 TEST(QuicTimeDeltaTest, Max) { | 70 TEST(QuicTimeDeltaTest, Max) { |
| 65 EXPECT_EQ(QuicTime::Delta::FromMicroseconds(2000), | 71 EXPECT_EQ(QuicTime::Delta::FromMicroseconds(2000), |
| 66 std::max(QuicTime::Delta::FromMicroseconds(1000), | 72 std::max(QuicTime::Delta::FromMicroseconds(1000), |
| 67 QuicTime::Delta::FromMicroseconds(2000))); | 73 QuicTime::Delta::FromMicroseconds(2000))); |
| 68 } | 74 } |
| 69 | 75 |
| 70 TEST(QuicTimeDeltaTest, NotEqual) { | 76 TEST(QuicTimeDeltaTest, NotEqual) { |
| 71 EXPECT_TRUE(QuicTime::Delta::FromSeconds(0) != | 77 EXPECT_TRUE(QuicTime::Delta::FromSeconds(0) != |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 const QuicTime zero = QuicTime::Zero(); | 157 const QuicTime zero = QuicTime::Zero(); |
| 152 const QuicTime one = zero + QuicTime::Delta::FromSeconds(1); | 158 const QuicTime one = zero + QuicTime::Delta::FromSeconds(1); |
| 153 EXPECT_TRUE(zero <= zero); | 159 EXPECT_TRUE(zero <= zero); |
| 154 EXPECT_TRUE(zero <= one); | 160 EXPECT_TRUE(zero <= one); |
| 155 EXPECT_TRUE(one <= one); | 161 EXPECT_TRUE(one <= one); |
| 156 EXPECT_FALSE(one <= zero); | 162 EXPECT_FALSE(one <= zero); |
| 157 } | 163 } |
| 158 | 164 |
| 159 } // namespace test | 165 } // namespace test |
| 160 } // namespace net | 166 } // namespace net |
| OLD | NEW |