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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_match_unittest.cc

Issue 10911188: autocomplete: Add AutocompleteMatch::MergeClassifications() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: if one of the vectors is non-empty, return it Created 8 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 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 "chrome/browser/autocomplete/autocomplete_match.h" 5 #include "chrome/browser/autocomplete/autocomplete_match.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 TEST(AutocompleteMatchTest, MoreRelevant) { 10 TEST(AutocompleteMatchTest, MoreRelevant) {
(...skipping 13 matching lines...) Expand all
24 AutocompleteMatch m1(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED); 24 AutocompleteMatch m1(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED);
25 AutocompleteMatch m2(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED); 25 AutocompleteMatch m2(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED);
26 26
27 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 27 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
28 m1.relevance = cases[i].r1; 28 m1.relevance = cases[i].r1;
29 m2.relevance = cases[i].r2; 29 m2.relevance = cases[i].r2;
30 EXPECT_EQ(cases[i].expected_result, 30 EXPECT_EQ(cases[i].expected_result,
31 AutocompleteMatch::MoreRelevant(m1, m2)); 31 AutocompleteMatch::MoreRelevant(m1, m2));
32 } 32 }
33 } 33 }
34
35 TEST(AutocompleteMatchTest, MergeClassifications) {
36 // Merging two empty vectors should result in an empty vector.
37 EXPECT_EQ("",
Peter Kasting 2012/09/10 23:34:35 Nit: "" -> std::string()
Daniel Erat 2012/09/10 23:46:05 Done.
38 AutocompleteMatch::ClassificationsToString(
39 AutocompleteMatch::MergeClassifications(
40 AutocompleteMatch::ACMatchClassifications(),
41 AutocompleteMatch::ACMatchClassifications())));
42
43 // If one vector is empty and the other is "trivial" but non-empty (i.e. (0,
44 // NONE)), the non-empty vector should be returned.
45 EXPECT_EQ("0,0",
46 AutocompleteMatch::ClassificationsToString(
47 AutocompleteMatch::MergeClassifications(
48 AutocompleteMatch::ClassificationsFromString("0,0"),
49 AutocompleteMatch::ACMatchClassifications())));
50 EXPECT_EQ("0,0",
51 AutocompleteMatch::ClassificationsToString(
52 AutocompleteMatch::MergeClassifications(
53 AutocompleteMatch::ACMatchClassifications(),
54 AutocompleteMatch::ClassificationsFromString("0,0"))));
55
56 // Ditto if the one-entry vector is non-trivial.
57 EXPECT_EQ("0,1",
58 AutocompleteMatch::ClassificationsToString(
59 AutocompleteMatch::MergeClassifications(
60 AutocompleteMatch::ClassificationsFromString("0,1"),
61 AutocompleteMatch::ACMatchClassifications())));
62 EXPECT_EQ("0,1",
Peter Kasting 2012/09/10 23:34:35 Nit: Might want to change one of these cases (or a
Daniel Erat 2012/09/10 23:46:05 Done.
63 AutocompleteMatch::ClassificationsToString(
64 AutocompleteMatch::MergeClassifications(
65 AutocompleteMatch::ACMatchClassifications(),
66 AutocompleteMatch::ClassificationsFromString("0,1"))));
67
68 // Test simple cases of overlap.
69 EXPECT_EQ("0,3," "1,2",
70 AutocompleteMatch::ClassificationsToString(
71 AutocompleteMatch::MergeClassifications(
72 AutocompleteMatch::ClassificationsFromString("0,1," "1,0"),
73 AutocompleteMatch::ClassificationsFromString("0,2"))));
74 EXPECT_EQ("0,3," "1,2",
75 AutocompleteMatch::ClassificationsToString(
76 AutocompleteMatch::MergeClassifications(
77 AutocompleteMatch::ClassificationsFromString("0,2"),
78 AutocompleteMatch::ClassificationsFromString("0,1," "1,0"))));
79
80 // Test the case where both vectors have classifications at the same
81 // positions.
82 EXPECT_EQ("0,3",
83 AutocompleteMatch::ClassificationsToString(
84 AutocompleteMatch::MergeClassifications(
85 AutocompleteMatch::ClassificationsFromString("0,1," "1,2"),
86 AutocompleteMatch::ClassificationsFromString("0,2," "1,1"))));
87
88 // Test an arbitrary complicated case.
89 EXPECT_EQ("0,2," "1,0," "2,1," "4,3," "5,7," "6,3," "7,7," "15,1," "17,0",
90 AutocompleteMatch::ClassificationsToString(
91 AutocompleteMatch::MergeClassifications(
92 AutocompleteMatch::ClassificationsFromString(
93 "0,0," "2,1," "4,3," "7,7," "10,6," "15,0"),
94 AutocompleteMatch::ClassificationsFromString(
95 "0,2," "1,0," "5,7," "6,1," "17,0"))));
96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698