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

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

Issue 1814753002: Moved sequence number specific operations from mod_ops.h (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase Created 4 years, 9 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/base/mod_ops.h ('k') | webrtc/modules/modules.gyp » ('j') | 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 18 matching lines...) Expand all
29 int t = 37; 29 int t = 37;
30 uint8_t a = t; 30 uint8_t a = t;
31 for (int i = 0; i < 256; ++i) { 31 for (int i = 0; i < 256; ++i) {
32 ASSERT_EQ(a, static_cast<uint8_t>(t)); 32 ASSERT_EQ(a, static_cast<uint8_t>(t));
33 t = Add<256>(t, 1); 33 t = Add<256>(t, 1);
34 ++a; 34 ++a;
35 } 35 }
36 } 36 }
37 37
38 TEST_F(TestModOps, AddLarge) { 38 TEST_F(TestModOps, AddLarge) {
39 // NOLINTNEXTLINE
40 const unsigned long D = ulmax - 10ul; // NOLINT 39 const unsigned long D = ulmax - 10ul; // NOLINT
41 unsigned long l = D - 1ul; // NOLINT 40 unsigned long l = D - 1ul; // NOLINT
42 ASSERT_EQ(D - 2ul, Add<D>(l, l)); 41 ASSERT_EQ(D - 2ul, Add<D>(l, l));
43 ASSERT_EQ(9ul, Add<D>(l, ulmax)); 42 ASSERT_EQ(9ul, Add<D>(l, ulmax));
44 ASSERT_EQ(10ul, Add<D>(0ul, ulmax)); 43 ASSERT_EQ(10ul, Add<D>(0ul, ulmax));
45 } 44 }
46 45
47 TEST_F(TestModOps, Subtract) { 46 TEST_F(TestModOps, Subtract) {
48 const int D = 100; 47 const int D = 100;
49 ASSERT_EQ(99u, Subtract<D>(0, 1)); 48 ASSERT_EQ(99u, Subtract<D>(0, 1));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 99 }
101 100
102 int yi = 255; 101 int yi = 255;
103 for (int i = 0; i < 256; ++i) { 102 for (int i = 0; i < 256; ++i) {
104 ASSERT_EQ(1u, ReverseDiff<uint8_t>(x, yi)); 103 ASSERT_EQ(1u, ReverseDiff<uint8_t>(x, yi));
105 ++x; 104 ++x;
106 ++yi; 105 ++yi;
107 } 106 }
108 } 107 }
109 108
110 TEST_F(TestModOps, AheadOrAt) { 109 TEST_F(TestModOps, MinDiff) {
111 uint8_t x = 0; 110 for (uint16_t i = 0; i < 256; ++i) {
112 uint8_t y = 0; 111 ASSERT_EQ(0, MinDiff<uint8_t>(i, i));
113 ASSERT_TRUE(AheadOrAt(x, y)); 112 ASSERT_EQ(1, MinDiff<uint8_t>(i - 1, i));
114 ++x; 113 ASSERT_EQ(1, MinDiff<uint8_t>(i + 1, i));
115 ASSERT_TRUE(AheadOrAt(x, y));
116 ASSERT_FALSE(AheadOrAt(y, x));
117 for (int i = 0; i < 256; ++i) {
118 ASSERT_TRUE(AheadOrAt(x, y));
119 ++x;
120 ++y;
121 } 114 }
122 115
123 x = 128; 116 for (uint8_t i = 0; i < 128; ++i)
124 y = 0; 117 ASSERT_EQ(i, MinDiff<uint8_t>(0, i));
125 ASSERT_TRUE(AheadOrAt(x, y));
126 ASSERT_FALSE(AheadOrAt(y, x));
127 118
128 x = 129; 119 for (uint8_t i = 0; i < 128; ++i)
129 ASSERT_FALSE(AheadOrAt(x, y)); 120 ASSERT_EQ(128 - i, MinDiff<uint8_t>(0, 128 + i));
130 ASSERT_TRUE(AheadOrAt(y, x));
131 ASSERT_TRUE(AheadOrAt<uint16_t>(x, y));
132 ASSERT_FALSE(AheadOrAt<uint16_t>(y, x));
133 } 121 }
134 122
135 TEST_F(TestModOps, AheadOf) { 123 TEST_F(TestModOps, MinDiffWitDivisor) {
136 uint8_t x = 0; 124 ASSERT_EQ(5u, (MinDiff<uint8_t, 11>(0, 5)));
137 uint8_t y = 0; 125 ASSERT_EQ(5u, (MinDiff<uint8_t, 11>(0, 6)));
138 ASSERT_FALSE(AheadOf(x, y)); 126 ASSERT_EQ(5u, (MinDiff<uint8_t, 11>(5, 0)));
139 ++x; 127 ASSERT_EQ(5u, (MinDiff<uint8_t, 11>(6, 0)));
140 ASSERT_TRUE(AheadOf(x, y));
141 ASSERT_FALSE(AheadOf(y, x));
142 for (int i = 0; i < 256; ++i) {
143 ASSERT_TRUE(AheadOf(x, y));
144 ++x;
145 ++y;
146 }
147 128
148 x = 128; 129 const uint16_t D = 4711;
149 y = 0;
150 for (int i = 0; i < 128; ++i) {
151 ASSERT_TRUE(AheadOf(x, y));
152 ASSERT_FALSE(AheadOf(y, x));
153 x++;
154 y++;
155 }
156 130
157 for (int i = 0; i < 128; ++i) { 131 for (uint16_t i = 0; i < D / 2; ++i)
158 ASSERT_FALSE(AheadOf(x, y)); 132 ASSERT_EQ(i, (MinDiff<uint16_t, D>(0, i)));
159 ASSERT_TRUE(AheadOf(y, x));
160 x++;
161 y++;
162 }
163 133
164 x = 129; 134 ASSERT_EQ(D / 2, (MinDiff<uint16_t, D>(0, D / 2)));
165 y = 0;
166 ASSERT_FALSE(AheadOf(x, y));
167 ASSERT_TRUE(AheadOf(y, x));
168 ASSERT_TRUE(AheadOf<uint16_t>(x, y));
169 ASSERT_FALSE(AheadOf<uint16_t>(y, x));
170 }
171 135
172 TEST_F(TestModOps, ForwardDiffWithDivisor) { 136 for (uint16_t i = 0; i < D / 2; ++i)
173 const uint8_t kDivisor = 211; 137 ASSERT_EQ(D / 2 - i, (MinDiff<uint16_t, D>(0, D / 2 - i)));
174
175 for (uint8_t i = 0; i < kDivisor - 1; ++i) {
176 ASSERT_EQ(0, (ForwardDiff<uint8_t, kDivisor>(i, i)));
177 ASSERT_EQ(1, (ForwardDiff<uint8_t, kDivisor>(i, i + 1)));
178 ASSERT_EQ(kDivisor - 1, (ForwardDiff<uint8_t, kDivisor>(i + 1, i)));
179 }
180
181 for (uint8_t i = 1; i < kDivisor; ++i) {
182 ASSERT_EQ(i, (ForwardDiff<uint8_t, kDivisor>(0, i)));
183 ASSERT_EQ(kDivisor - i, (ForwardDiff<uint8_t, kDivisor>(i, 0)));
184 }
185 }
186
187 TEST_F(TestModOps, ReverseDiffWithDivisor) {
188 const uint8_t kDivisor = 241;
189
190 for (uint8_t i = 0; i < kDivisor - 1; ++i) {
191 ASSERT_EQ(0, (ReverseDiff<uint8_t, kDivisor>(i, i)));
192 ASSERT_EQ(kDivisor - 1, (ReverseDiff<uint8_t, kDivisor>(i, i + 1)));
193 ASSERT_EQ(1, (ReverseDiff<uint8_t, kDivisor>(i + 1, i)));
194 }
195
196 for (uint8_t i = 1; i < kDivisor; ++i) {
197 ASSERT_EQ(kDivisor - i, (ReverseDiff<uint8_t, kDivisor>(0, i)));
198 ASSERT_EQ(i, (ReverseDiff<uint8_t, kDivisor>(i, 0)));
199 }
200 } 138 }
201 139
202 } // namespace webrtc 140 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/base/mod_ops.h ('k') | webrtc/modules/modules.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698