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

Unified Diff: components/enhanced_bookmarks/item_position_unittest.cc

Issue 510543002: Introduce ItemPosition class for enhanced bookmarks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Rename to ItemPosition Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/enhanced_bookmarks/item_position.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/enhanced_bookmarks/item_position_unittest.cc
diff --git a/components/enhanced_bookmarks/item_position_unittest.cc b/components/enhanced_bookmarks/item_position_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2321e0ccfc8c539df0a43f24ce219e8ea276e90a
--- /dev/null
+++ b/components/enhanced_bookmarks/item_position_unittest.cc
@@ -0,0 +1,81 @@
+// Copyright 2014 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.
+
+#include "components/enhanced_bookmarks/item_position.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+using enhanced_bookmarks::ItemPosition;
+
+namespace {
+
+class ItemPositionTest : public testing::Test {};
+
+TEST_F(ItemPositionTest, TestCreateBefore) {
+ ItemPosition current = ItemPosition::CreateInitialPosition();
+ for (int i = 0; i < 10000; i++) {
+ ItemPosition next = ItemPosition::CreateBefore(current);
+ EXPECT_LT(next.ToString(), current.ToString());
+ current = next;
+ }
+ // Make sure string lengths stay reasonable.
+ EXPECT_LT(current.ToString().size(), 20u);
+}
+
+TEST_F(ItemPositionTest, TestCreateAfter) {
+ ItemPosition current = ItemPosition::CreateInitialPosition();
+ for (int i = 0; i < 10000; i++) {
+ ItemPosition next = ItemPosition::CreateAfter(current);
+ EXPECT_GT(next.ToString(), current.ToString());
+ current = next;
+ }
+ // Make sure string lengths stay reasonable.
+ EXPECT_LT(current.ToString().size(), 20u);
+}
+
+TEST_F(ItemPositionTest, TestCreateBetweenLeftBias) {
+ ItemPosition before = ItemPosition::CreateInitialPosition();
+ ItemPosition after = ItemPosition::CreateAfter(before);
+ for (int i = 0; i < 10000; i++) {
+ ItemPosition next = ItemPosition::CreateBetween(before, after);
+ EXPECT_GT(next.ToString(), before.ToString());
+ EXPECT_LT(next.ToString(), after.ToString());
+ after = next;
+ }
+ // Make sure string lengths stay reasonable.
+ EXPECT_LT(after.ToString().size(), 20u);
+}
+
+TEST_F(ItemPositionTest, TestCreateBetweenRightBias) {
+ ItemPosition before = ItemPosition::CreateInitialPosition();
+ ItemPosition after = ItemPosition::CreateAfter(before);
+ for (int i = 0; i < 10000; i++) {
+ ItemPosition next = ItemPosition::CreateBetween(before, after);
+ EXPECT_GT(next.ToString(), before.ToString());
+ EXPECT_LT(next.ToString(), after.ToString());
+ before = next;
+ }
+ // Make sure string lengths stay reasonable.
+ EXPECT_LT(before.ToString().size(), 20u);
+}
+
+TEST_F(ItemPositionTest, TestCreateBetweenAlternating) {
+ ItemPosition before = ItemPosition::CreateInitialPosition();
+ ItemPosition after = ItemPosition::CreateAfter(before);
+ for (int i = 0; i < 1000; i++) {
+ ItemPosition next = ItemPosition::CreateBetween(before, after);
+ EXPECT_GT(next.ToString(), before.ToString());
+ EXPECT_LT(next.ToString(), after.ToString());
+ if ((i & 1) == 1)
+ before = next;
+ else
+ after = next;
+ }
+ // There's no way to keep the string length down for all possible insertion
+ // scenarios, and this one should be fairly rare in practice. Still verify
+ // that at least the growth is restricted to about n*log_2(kPositionBase).
+ EXPECT_LT(before.ToString().size(), 200u);
+}
+
+} // namespace
« no previous file with comments | « components/enhanced_bookmarks/item_position.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698