[AndroidWebViewShell] Replace rebaseline script with a new version using test_runner.py
[chromium-blink-merge.git] / components / enhanced_bookmarks / item_position_unittest.cc
blob2321e0ccfc8c539df0a43f24ce219e8ea276e90a
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/enhanced_bookmarks/item_position.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 using enhanced_bookmarks::ItemPosition;
11 namespace {
13 class ItemPositionTest : public testing::Test {};
15 TEST_F(ItemPositionTest, TestCreateBefore) {
16 ItemPosition current = ItemPosition::CreateInitialPosition();
17 for (int i = 0; i < 10000; i++) {
18 ItemPosition next = ItemPosition::CreateBefore(current);
19 EXPECT_LT(next.ToString(), current.ToString());
20 current = next;
22 // Make sure string lengths stay reasonable.
23 EXPECT_LT(current.ToString().size(), 20u);
26 TEST_F(ItemPositionTest, TestCreateAfter) {
27 ItemPosition current = ItemPosition::CreateInitialPosition();
28 for (int i = 0; i < 10000; i++) {
29 ItemPosition next = ItemPosition::CreateAfter(current);
30 EXPECT_GT(next.ToString(), current.ToString());
31 current = next;
33 // Make sure string lengths stay reasonable.
34 EXPECT_LT(current.ToString().size(), 20u);
37 TEST_F(ItemPositionTest, TestCreateBetweenLeftBias) {
38 ItemPosition before = ItemPosition::CreateInitialPosition();
39 ItemPosition after = ItemPosition::CreateAfter(before);
40 for (int i = 0; i < 10000; i++) {
41 ItemPosition next = ItemPosition::CreateBetween(before, after);
42 EXPECT_GT(next.ToString(), before.ToString());
43 EXPECT_LT(next.ToString(), after.ToString());
44 after = next;
46 // Make sure string lengths stay reasonable.
47 EXPECT_LT(after.ToString().size(), 20u);
50 TEST_F(ItemPositionTest, TestCreateBetweenRightBias) {
51 ItemPosition before = ItemPosition::CreateInitialPosition();
52 ItemPosition after = ItemPosition::CreateAfter(before);
53 for (int i = 0; i < 10000; i++) {
54 ItemPosition next = ItemPosition::CreateBetween(before, after);
55 EXPECT_GT(next.ToString(), before.ToString());
56 EXPECT_LT(next.ToString(), after.ToString());
57 before = next;
59 // Make sure string lengths stay reasonable.
60 EXPECT_LT(before.ToString().size(), 20u);
63 TEST_F(ItemPositionTest, TestCreateBetweenAlternating) {
64 ItemPosition before = ItemPosition::CreateInitialPosition();
65 ItemPosition after = ItemPosition::CreateAfter(before);
66 for (int i = 0; i < 1000; i++) {
67 ItemPosition next = ItemPosition::CreateBetween(before, after);
68 EXPECT_GT(next.ToString(), before.ToString());
69 EXPECT_LT(next.ToString(), after.ToString());
70 if ((i & 1) == 1)
71 before = next;
72 else
73 after = next;
75 // There's no way to keep the string length down for all possible insertion
76 // scenarios, and this one should be fairly rare in practice. Still verify
77 // that at least the growth is restricted to about n*log_2(kPositionBase).
78 EXPECT_LT(before.ToString().size(), 200u);
81 } // namespace