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

Unified Diff: base/bits_unittest.cc

Issue 373001: Moved bits.h from O3D to Chrome base. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/bits.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/bits_unittest.cc
===================================================================
--- base/bits_unittest.cc (revision 0)
+++ base/bits_unittest.cc (revision 0)
@@ -0,0 +1,48 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file contains the unit tests for the bit utilities.
+
+#include "base/bits.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+namespace bits {
+
+TEST(BitsTest, Log2Floor) {
+ EXPECT_EQ(-1, Log2Floor(0));
+ EXPECT_EQ(0, Log2Floor(1));
+ EXPECT_EQ(1, Log2Floor(2));
+ EXPECT_EQ(1, Log2Floor(3));
+ EXPECT_EQ(2, Log2Floor(4));
+ for (int i = 3; i < 31; ++i) {
+ unsigned int value = 1U << i;
+ EXPECT_EQ(i, Log2Floor(value));
+ EXPECT_EQ(i, Log2Floor(value + 1));
+ EXPECT_EQ(i, Log2Floor(value + 2));
+ EXPECT_EQ(i - 1, Log2Floor(value - 1));
+ EXPECT_EQ(i - 1, Log2Floor(value - 2));
+ }
+ EXPECT_EQ(31, Log2Floor(0xffffffffU));
+}
+
+TEST(BitsTest, Log2Ceiling) {
+ EXPECT_EQ(-1, Log2Ceiling(0));
+ EXPECT_EQ(0, Log2Ceiling(1));
+ EXPECT_EQ(1, Log2Ceiling(2));
+ EXPECT_EQ(2, Log2Ceiling(3));
+ EXPECT_EQ(2, Log2Ceiling(4));
+ for (int i = 3; i < 31; ++i) {
+ unsigned int value = 1U << i;
+ EXPECT_EQ(i, Log2Ceiling(value));
+ EXPECT_EQ(i + 1, Log2Ceiling(value + 1));
+ EXPECT_EQ(i + 1, Log2Ceiling(value + 2));
+ EXPECT_EQ(i, Log2Ceiling(value - 1));
+ EXPECT_EQ(i, Log2Ceiling(value - 2));
+ }
+ EXPECT_EQ(32, Log2Ceiling(0xffffffffU));
+}
+
+} // namespace bits
+} // namespace base
Property changes on: base\bits_unittest.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « base/bits.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698