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

Unified Diff: chrome/browser/autocomplete/scored_history_match_builder_impl_unittest.cc

Issue 905023003: Adding knobs on HQP provider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Float error fix Created 5 years, 10 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
Index: chrome/browser/autocomplete/scored_history_match_builder_impl_unittest.cc
diff --git a/chrome/browser/autocomplete/scored_history_match_builder_impl_unittest.cc b/chrome/browser/autocomplete/scored_history_match_builder_impl_unittest.cc
index 774735d31143191c837670610ccbd5bfd2df706b..406beeee81f769ea0131180f20dcee6f713c1202 100644
--- a/chrome/browser/autocomplete/scored_history_match_builder_impl_unittest.cc
+++ b/chrome/browser/autocomplete/scored_history_match_builder_impl_unittest.cc
@@ -10,9 +10,12 @@
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/autocomplete/scored_history_match_builder_impl.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::ASCIIToUTF16;
+using testing::ElementsAre;
+using testing::Pair;
namespace {
@@ -469,3 +472,62 @@ TEST_F(ScoredHistoryMatchBuilderImplTest, GetTopicalityScore) {
EXPECT_GT(hostname_mid_word_score, tld_score);
EXPECT_GT(hostname_mid_word_score, tld_mid_word_score);
}
+
+// Test the function GetFinalRelevancyScore().
+TEST_F(ScoredHistoryMatchBuilderImplTest, GetFinalRelevancyScore) {
+ // hqp_relevance_buckets = "0.0:100,1.0:200,4.0:500,8.0:900,10.0:1000";
+ std::vector<ScoredHistoryMatchBuilderImpl::ScoreMaxRelevance> hqp_buckets;
+ hqp_buckets.push_back(std::make_pair(0.0, 100));
+ hqp_buckets.push_back(std::make_pair(1.0, 200));
+ hqp_buckets.push_back(std::make_pair(4.0, 500));
+ hqp_buckets.push_back(std::make_pair(8.0, 900));
+ hqp_buckets.push_back(std::make_pair(10.0, 1000));
+ // Check when topicality score is zero.
+ float topicality_score = 0.0;
+ float frequency_score = 10.0;
+ // intermediate_score = 0.0 * 10.0 = 0.0.
+ EXPECT_EQ(0,
+ ScoredHistoryMatchBuilderImpl::GetFinalRelevancyScore(
+ topicality_score, frequency_score, hqp_buckets));
+
+ // Check when intermediate score falls at the border range.
+ topicality_score = 0.4f;
+ frequency_score = 10.0f;
+ // intermediate_score = 0.5 * 10.0 = 4.0.
+ EXPECT_EQ(500,
+ ScoredHistoryMatchBuilderImpl::GetFinalRelevancyScore(
+ topicality_score, frequency_score, hqp_buckets));
+
+ // Checking the score that falls into one of the buckets.
+ topicality_score = 0.5f;
+ frequency_score = 10.0f;
+ // intermediate_score = 0.5 * 10.0 = 5.0.
+ EXPECT_EQ(600, // 500 + (((900 - 500)/(8 -4)) * 1) = 600.
+ ScoredHistoryMatchBuilderImpl::GetFinalRelevancyScore(
+ topicality_score, frequency_score, hqp_buckets));
+
+ // Never give the score greater than maximum specified.
+ topicality_score = 0.5f;
+ frequency_score = 22.0f;
+ // intermediate_score = 0.5 * 22.0 = 11.0
+ EXPECT_EQ(1000,
+ ScoredHistoryMatchBuilderImpl::GetFinalRelevancyScore(
+ topicality_score, frequency_score, hqp_buckets));
+}
+
+// Test the function GetHQPBucketsFromString().
+TEST_F(ScoredHistoryMatchBuilderImplTest, GetHQPBucketsFromString) {
+ std::string buckets_str = "0.0:400,1.5:600,12.0:1300,20.0:1399";
+ std::vector<ScoredHistoryMatchBuilderImpl::ScoreMaxRelevance> hqp_buckets;
+
+ EXPECT_TRUE(ScoredHistoryMatchBuilderImpl::GetHQPBucketsFromString(
+ buckets_str, &hqp_buckets));
+ EXPECT_THAT(hqp_buckets, ElementsAre(Pair(0.0, 400),
+ Pair(1.5, 600),
+ Pair(12.0, 1300),
+ Pair(20.0, 1399)));
+ // invalid string.
+ buckets_str = "0.0,400,1.5,600";
+ EXPECT_FALSE(ScoredHistoryMatchBuilderImpl::GetHQPBucketsFromString(
+ buckets_str, &hqp_buckets));
+}
« no previous file with comments | « chrome/browser/autocomplete/scored_history_match_builder_impl.cc ('k') | components/omnibox/omnibox_field_trial.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698