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

Side by Side Diff: third_party/libaddressinput/chromium/cpp/test/util/trie_test.cc

Issue 389863002: Remove Chrome's own version of libaddressinput in favor of the upstream. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « third_party/libaddressinput/chromium/cpp/test/util/string_util_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (C) 2014 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "util/trie.h"
16
17 #include <set>
18 #include <string>
19
20 #include <gtest/gtest.h>
21
22 namespace i18n {
23 namespace addressinput {
24
25 namespace {
26
27 TEST(TrieTest, EmptyTrieHasNoData) {
28 Trie<std::string> trie;
29 std::set<std::string> result;
30 trie.FindDataForKeyPrefix("key", &result);
31 EXPECT_TRUE(result.empty());
32 }
33
34 TEST(TrieTest, CanGetDataByExactKey) {
35 Trie<std::string> trie;
36 trie.AddDataForKey("hello", "world");
37 std::set<std::string> result;
38 trie.FindDataForKeyPrefix("hello", &result);
39 std::set<std::string> expected;
40 expected.insert("world");
41 EXPECT_EQ(expected, result);
42 }
43
44 TEST(TrieTest, CanGetDataByPrefix) {
45 Trie<std::string> trie;
46 trie.AddDataForKey("hello", "world");
47 std::set<std::string> result;
48 trie.FindDataForKeyPrefix("he", &result);
49 std::set<std::string> expected;
50 expected.insert("world");
51 EXPECT_EQ(expected, result);
52 }
53
54 TEST(TrieTest, KeyTooLongNoData) {
55 Trie<std::string> trie;
56 trie.AddDataForKey("hello", "world");
57 std::set<std::string> result;
58 trie.FindDataForKeyPrefix("helloo", &result);
59 EXPECT_TRUE(result.empty());
60 }
61
62 TEST(TrieTest, CommonPrefixFindsMultipleData) {
63 Trie<std::string> trie;
64 trie.AddDataForKey("hello", "world");
65 trie.AddDataForKey("howdy", "buddy");
66 trie.AddDataForKey("foo", "bar");
67 std::set<std::string> results;
68 trie.FindDataForKeyPrefix("h", &results);
69 std::set<std::string> expected;
70 expected.insert("world");
71 expected.insert("buddy");
72 EXPECT_EQ(expected, results);
73 }
74
75 TEST(TrieTest, KeyCanBePrefixOfOtherKey) {
76 Trie<std::string> trie;
77 trie.AddDataForKey("hello", "world");
78 trie.AddDataForKey("helloo", "woorld");
79 trie.AddDataForKey("hella", "warld");
80 std::set<std::string> results;
81 trie.FindDataForKeyPrefix("hello", &results);
82 std::set<std::string> expected;
83 expected.insert("world");
84 expected.insert("woorld");
85 EXPECT_EQ(expected, results);
86 }
87
88 TEST(TrieTest, AllowMutlipleKeys) {
89 Trie<std::string> trie;
90 trie.AddDataForKey("hello", "world");
91 trie.AddDataForKey("hello", "woorld");
92 std::set<std::string> results;
93 trie.FindDataForKeyPrefix("hello", &results);
94 std::set<std::string> expected;
95 expected.insert("world");
96 expected.insert("woorld");
97 EXPECT_EQ(expected, results);
98 }
99
100 TEST(TrieTest, CanFindVeryLongKey) {
101 Trie<std::string> trie;
102 static const char kVeryLongKey[] = "1234567890qwertyuioasdfghj";
103 trie.AddDataForKey(kVeryLongKey, "world");
104 std::set<std::string> result;
105 trie.FindDataForKeyPrefix(kVeryLongKey, &result);
106 std::set<std::string> expected;
107 expected.insert("world");
108 EXPECT_EQ(expected, result);
109 }
110
111 } // namespace
112
113 } // namespace addressinput
114 } // namespace i18n
OLDNEW
« no previous file with comments | « third_party/libaddressinput/chromium/cpp/test/util/string_util_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698