Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(655)

Side by Side Diff: webrtc/rtc_base/mod_ops_unittest.cc

Issue 2977603002: Implemented a new sequence number unwrapper in sequence_number_util.h. (Closed)
Patch Set: Feedback Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/rtc_base/mod_ops.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 80 }
81 81
82 int yi = 255; 82 int yi = 255;
83 for (int i = 0; i < 256; ++i) { 83 for (int i = 0; i < 256; ++i) {
84 ASSERT_EQ(255u, ForwardDiff<uint8_t>(x, yi)); 84 ASSERT_EQ(255u, ForwardDiff<uint8_t>(x, yi));
85 ++x; 85 ++x;
86 ++yi; 86 ++yi;
87 } 87 }
88 } 88 }
89 89
90 TEST_F(TestModOps, ForwardDiffWithDivisor) {
91 ASSERT_EQ(122, (ForwardDiff<uint8_t, 123>(0, 122)));
92 ASSERT_EQ(0, (ForwardDiff<uint8_t, 123>(122, 122)));
93 ASSERT_EQ(122, (ForwardDiff<uint8_t, 123>(1, 0)));
94 ASSERT_EQ(0, (ForwardDiff<uint8_t, 123>(0, 0)));
95 ASSERT_EQ(1, (ForwardDiff<uint8_t, 123>(122, 0)));
96 }
97
90 TEST_F(TestModOps, ReverseDiff) { 98 TEST_F(TestModOps, ReverseDiff) {
91 ASSERT_EQ(0u, ReverseDiff(4711u, 4711u)); 99 ASSERT_EQ(0u, ReverseDiff(4711u, 4711u));
92 100
93 uint8_t x = 0; 101 uint8_t x = 0;
94 uint8_t y = 255; 102 uint8_t y = 255;
95 for (int i = 0; i < 256; ++i) { 103 for (int i = 0; i < 256; ++i) {
96 ASSERT_EQ(1u, ReverseDiff(x, y)); 104 ASSERT_EQ(1u, ReverseDiff(x, y));
97 ++x; 105 ++x;
98 ++y; 106 ++y;
99 } 107 }
100 108
101 int yi = 255; 109 int yi = 255;
102 for (int i = 0; i < 256; ++i) { 110 for (int i = 0; i < 256; ++i) {
103 ASSERT_EQ(1u, ReverseDiff<uint8_t>(x, yi)); 111 ASSERT_EQ(1u, ReverseDiff<uint8_t>(x, yi));
104 ++x; 112 ++x;
105 ++yi; 113 ++yi;
106 } 114 }
107 } 115 }
108 116
117 TEST_F(TestModOps, ReverseDiffWithDivisor) {
118 ASSERT_EQ(1, (ReverseDiff<uint8_t, 123>(0, 122)));
119 ASSERT_EQ(0, (ReverseDiff<uint8_t, 123>(122, 122)));
120 ASSERT_EQ(1, (ReverseDiff<uint8_t, 123>(1, 0)));
121 ASSERT_EQ(0, (ReverseDiff<uint8_t, 123>(0, 0)));
122 ASSERT_EQ(122, (ReverseDiff<uint8_t, 123>(122, 0)));
123 }
124
109 TEST_F(TestModOps, MinDiff) { 125 TEST_F(TestModOps, MinDiff) {
110 for (uint16_t i = 0; i < 256; ++i) { 126 for (uint16_t i = 0; i < 256; ++i) {
111 ASSERT_EQ(0, MinDiff<uint8_t>(i, i)); 127 ASSERT_EQ(0, MinDiff<uint8_t>(i, i));
112 ASSERT_EQ(1, MinDiff<uint8_t>(i - 1, i)); 128 ASSERT_EQ(1, MinDiff<uint8_t>(i - 1, i));
113 ASSERT_EQ(1, MinDiff<uint8_t>(i + 1, i)); 129 ASSERT_EQ(1, MinDiff<uint8_t>(i + 1, i));
114 } 130 }
115 131
116 for (uint8_t i = 0; i < 128; ++i) 132 for (uint8_t i = 0; i < 128; ++i)
117 ASSERT_EQ(i, MinDiff<uint8_t>(0, i)); 133 ASSERT_EQ(i, MinDiff<uint8_t>(0, i));
118 134
(...skipping 12 matching lines...) Expand all
131 for (uint16_t i = 0; i < D / 2; ++i) 147 for (uint16_t i = 0; i < D / 2; ++i)
132 ASSERT_EQ(i, (MinDiff<uint16_t, D>(0, i))); 148 ASSERT_EQ(i, (MinDiff<uint16_t, D>(0, i)));
133 149
134 ASSERT_EQ(D / 2, (MinDiff<uint16_t, D>(0, D / 2))); 150 ASSERT_EQ(D / 2, (MinDiff<uint16_t, D>(0, D / 2)));
135 151
136 for (uint16_t i = 0; i < D / 2; ++i) 152 for (uint16_t i = 0; i < D / 2; ++i)
137 ASSERT_EQ(D / 2 - i, (MinDiff<uint16_t, D>(0, D / 2 - i))); 153 ASSERT_EQ(D / 2 - i, (MinDiff<uint16_t, D>(0, D / 2 - i)));
138 } 154 }
139 155
140 } // namespace webrtc 156 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/rtc_base/mod_ops.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698