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

Side by Side Diff: net/base/int128_unittest.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "net/base/int128.h" 7 #include "net/base/int128.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10
11 TEST(Int128, AllTests) { 10 TEST(Int128, AllTests) {
12 uint128 zero(0); 11 uint128 zero(0);
13 uint128 one(1); 12 uint128 one(1);
14 uint128 one_2arg(0, 1); 13 uint128 one_2arg(0, 1);
15 uint128 two(0, 2); 14 uint128 two(0, 2);
16 uint128 three(0, 3); 15 uint128 three(0, 3);
17 uint128 big(2000, 2); 16 uint128 big(2000, 2);
18 uint128 big_minus_one(2000, 1); 17 uint128 big_minus_one(2000, 1);
19 uint128 bigger(2001, 1); 18 uint128 bigger(2001, 1);
20 uint128 biggest(kuint128max); 19 uint128 biggest(kuint128max);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 EXPECT_EQ(big, -(-big)); 107 EXPECT_EQ(big, -(-big));
109 EXPECT_EQ(two, -((-one) - 1)); 108 EXPECT_EQ(two, -((-one) - 1));
110 EXPECT_EQ(kuint128max, -one); 109 EXPECT_EQ(kuint128max, -one);
111 EXPECT_EQ(zero, -zero); 110 EXPECT_EQ(zero, -zero);
112 111
113 LOG(INFO) << one; 112 LOG(INFO) << one;
114 LOG(INFO) << big_minus_one; 113 LOG(INFO) << big_minus_one;
115 } 114 }
116 115
117 TEST(Int128, PodTests) { 116 TEST(Int128, PodTests) {
118 uint128_pod pod = { 12345, 67890 }; 117 uint128_pod pod = {12345, 67890};
119 uint128 from_pod(pod); 118 uint128 from_pod(pod);
120 EXPECT_EQ(12345u, Uint128High64(from_pod)); 119 EXPECT_EQ(12345u, Uint128High64(from_pod));
121 EXPECT_EQ(67890u, Uint128Low64(from_pod)); 120 EXPECT_EQ(67890u, Uint128Low64(from_pod));
122 121
123 uint128 zero(0); 122 uint128 zero(0);
124 uint128_pod zero_pod = {0, 0}; 123 uint128_pod zero_pod = {0, 0};
125 uint128 one(1); 124 uint128 one(1);
126 uint128_pod one_pod = {0, 1}; 125 uint128_pod one_pod = {0, 1};
127 uint128 two(2); 126 uint128 two(2);
128 uint128_pod two_pod = {0, 2}; 127 uint128_pod two_pod = {0, 2};
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 c = uint128(0) - 1; 217 c = uint128(0) - 1;
219 c *= c; 218 c *= c;
220 EXPECT_EQ(1, c); 219 EXPECT_EQ(1, c);
221 220
222 // 1-bit x 1-bit. 221 // 1-bit x 1-bit.
223 for (int i = 0; i < 64; ++i) { 222 for (int i = 0; i < 64; ++i) {
224 for (int j = 0; j < 64; ++j) { 223 for (int j = 0; j < 64; ++j) {
225 a = uint128(1) << i; 224 a = uint128(1) << i;
226 b = uint128(1) << j; 225 b = uint128(1) << j;
227 c = a * b; 226 c = a * b;
228 EXPECT_EQ(uint128(1) << (i+j), c); 227 EXPECT_EQ(uint128(1) << (i + j), c);
229 } 228 }
230 } 229 }
231 230
232 // Verified with dc. 231 // Verified with dc.
233 a = uint128(0xffffeeeeddddccccULL, 0xbbbbaaaa99998888ULL); 232 a = uint128(0xffffeeeeddddccccULL, 0xbbbbaaaa99998888ULL);
234 b = uint128(0x7777666655554444ULL, 0x3333222211110000ULL); 233 b = uint128(0x7777666655554444ULL, 0x3333222211110000ULL);
235 c = a * b; 234 c = a * b;
236 EXPECT_EQ(uint128(0x530EDA741C71D4C3ULL, 0xBF25975319080000ULL), c); 235 EXPECT_EQ(uint128(0x530EDA741C71D4C3ULL, 0xBF25975319080000ULL), c);
237 EXPECT_EQ(0, c - b * a); 236 EXPECT_EQ(0, c - b * a);
238 EXPECT_EQ(a*a - b*b, (a+b) * (a-b)); 237 EXPECT_EQ(a * a - b * b, (a + b) * (a - b));
239 238
240 // Verified with dc. 239 // Verified with dc.
241 a = uint128(0x0123456789abcdefULL, 0xfedcba9876543210ULL); 240 a = uint128(0x0123456789abcdefULL, 0xfedcba9876543210ULL);
242 b = uint128(0x02468ace13579bdfULL, 0xfdb97531eca86420ULL); 241 b = uint128(0x02468ace13579bdfULL, 0xfdb97531eca86420ULL);
243 c = a * b; 242 c = a * b;
244 EXPECT_EQ(uint128(0x97a87f4f261ba3f2ULL, 0x342d0bbf48948200ULL), c); 243 EXPECT_EQ(uint128(0x97a87f4f261ba3f2ULL, 0x342d0bbf48948200ULL), c);
245 EXPECT_EQ(0, c - b * a); 244 EXPECT_EQ(0, c - b * a);
246 EXPECT_EQ(a*a - b*b, (a+b) * (a-b)); 245 EXPECT_EQ(a * a - b * b, (a + b) * (a - b));
247 } 246 }
248 247
249 TEST(Int128, AliasTests) { 248 TEST(Int128, AliasTests) {
250 uint128 x1(1, 2); 249 uint128 x1(1, 2);
251 uint128 x2(2, 4); 250 uint128 x2(2, 4);
252 x1 += x1; 251 x1 += x1;
253 EXPECT_EQ(x2, x1); 252 EXPECT_EQ(x2, x1);
254 253
255 uint128 x3(1, 1ull << 63); 254 uint128 x3(1, 1ull << 63);
256 uint128 x4(3, 0); 255 uint128 x4(3, 0);
257 x3 += x3; 256 x3 += x3;
258 EXPECT_EQ(x4, x3); 257 EXPECT_EQ(x4, x3);
259 } 258 }
OLDNEW
« no previous file with comments | « net/base/int128.cc ('k') | net/base/io_buffer.cc » ('j') | net/base/mime_sniffer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698