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

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: mod_ops unittests Created 3 years, 5 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
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 const uint8_t kDiv = 123;
92 uint8_t x = 0;
93 uint8_t y = kDiv - 1;
94 for (int i = 0; i < kDiv; ++i) {
95 ASSERT_EQ(kDiv - 1, (ForwardDiff<uint8_t, kDiv>(x, y)));
96 x = (x + 1) % kDiv;
97 y = (y + 1) % kDiv;
98 }
99 }
100
90 TEST_F(TestModOps, ReverseDiff) { 101 TEST_F(TestModOps, ReverseDiff) {
91 ASSERT_EQ(0u, ReverseDiff(4711u, 4711u)); 102 ASSERT_EQ(0u, ReverseDiff(4711u, 4711u));
92 103
93 uint8_t x = 0; 104 uint8_t x = 0;
94 uint8_t y = 255; 105 uint8_t y = 255;
95 for (int i = 0; i < 256; ++i) { 106 for (int i = 0; i < 256; ++i) {
96 ASSERT_EQ(1u, ReverseDiff(x, y)); 107 ASSERT_EQ(1u, ReverseDiff(x, y));
97 ++x; 108 ++x;
98 ++y; 109 ++y;
99 } 110 }
100 111
101 int yi = 255; 112 int yi = 255;
102 for (int i = 0; i < 256; ++i) { 113 for (int i = 0; i < 256; ++i) {
103 ASSERT_EQ(1u, ReverseDiff<uint8_t>(x, yi)); 114 ASSERT_EQ(1u, ReverseDiff<uint8_t>(x, yi));
104 ++x; 115 ++x;
105 ++yi; 116 ++yi;
106 } 117 }
107 } 118 }
108 119
120 TEST_F(TestModOps, ReverseDiffWithDivisor) {
121 const uint8_t kDiv = 13;
122 uint8_t x = 0;
123 uint8_t y = kDiv - 1;
124 for (int i = 0; i < kDiv; ++i) {
125 ASSERT_EQ(1, (ReverseDiff<uint8_t, kDiv>(x, y)));
126 x = (x + 1) % kDiv;
127 y = (y + 1) % kDiv;
128 }
129 }
130
109 TEST_F(TestModOps, MinDiff) { 131 TEST_F(TestModOps, MinDiff) {
110 for (uint16_t i = 0; i < 256; ++i) { 132 for (uint16_t i = 0; i < 256; ++i) {
111 ASSERT_EQ(0, MinDiff<uint8_t>(i, i)); 133 ASSERT_EQ(0, MinDiff<uint8_t>(i, i));
112 ASSERT_EQ(1, MinDiff<uint8_t>(i - 1, i)); 134 ASSERT_EQ(1, MinDiff<uint8_t>(i - 1, i));
113 ASSERT_EQ(1, MinDiff<uint8_t>(i + 1, i)); 135 ASSERT_EQ(1, MinDiff<uint8_t>(i + 1, i));
114 } 136 }
115 137
116 for (uint8_t i = 0; i < 128; ++i) 138 for (uint8_t i = 0; i < 128; ++i)
117 ASSERT_EQ(i, MinDiff<uint8_t>(0, i)); 139 ASSERT_EQ(i, MinDiff<uint8_t>(0, i));
118 140
(...skipping 12 matching lines...) Expand all
131 for (uint16_t i = 0; i < D / 2; ++i) 153 for (uint16_t i = 0; i < D / 2; ++i)
132 ASSERT_EQ(i, (MinDiff<uint16_t, D>(0, i))); 154 ASSERT_EQ(i, (MinDiff<uint16_t, D>(0, i)));
133 155
134 ASSERT_EQ(D / 2, (MinDiff<uint16_t, D>(0, D / 2))); 156 ASSERT_EQ(D / 2, (MinDiff<uint16_t, D>(0, D / 2)));
135 157
136 for (uint16_t i = 0; i < D / 2; ++i) 158 for (uint16_t i = 0; i < D / 2; ++i)
137 ASSERT_EQ(D / 2 - i, (MinDiff<uint16_t, D>(0, D / 2 - i))); 159 ASSERT_EQ(D / 2 - i, (MinDiff<uint16_t, D>(0, D / 2 - i)));
138 } 160 }
139 161
140 } // namespace webrtc 162 } // namespace webrtc
OLDNEW
« webrtc/modules/video_coding/sequence_number_util_unittest.cc ('K') | « webrtc/rtc_base/mod_ops.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698