| OLD | NEW |
| 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 "components/omnibox/browser/scored_history_match.h" | 5 #include "components/omnibox/browser/scored_history_match.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 // matches (.com, .net, etc.) score worse than some of the mid-word | 640 // matches (.com, .net, etc.) score worse than some of the mid-word |
| 641 // matches that actually count. | 641 // matches that actually count. |
| 642 EXPECT_GT(hostname_mid_word_score, protocol_score); | 642 EXPECT_GT(hostname_mid_word_score, protocol_score); |
| 643 EXPECT_GT(hostname_mid_word_score, protocol_mid_word_score); | 643 EXPECT_GT(hostname_mid_word_score, protocol_mid_word_score); |
| 644 EXPECT_GT(hostname_mid_word_score, tld_score); | 644 EXPECT_GT(hostname_mid_word_score, tld_score); |
| 645 EXPECT_GT(hostname_mid_word_score, tld_mid_word_score); | 645 EXPECT_GT(hostname_mid_word_score, tld_mid_word_score); |
| 646 } | 646 } |
| 647 | 647 |
| 648 // Test the function GetFinalRelevancyScore(). | 648 // Test the function GetFinalRelevancyScore(). |
| 649 TEST_F(ScoredHistoryMatchTest, GetFinalRelevancyScore) { | 649 TEST_F(ScoredHistoryMatchTest, GetFinalRelevancyScore) { |
| 650 // hqp_relevance_buckets = "0.0:100,1.0:200,4.0:500,8.0:900,10.0:1000"; | 650 // relevance_buckets = "0.0:100,1.0:200,4.0:500,8.0:900,10.0:1000"; |
| 651 std::vector<ScoredHistoryMatch::ScoreMaxRelevance> hqp_buckets; | 651 ScoredHistoryMatch::ScoreMaxRelevances relevance_buckets = { |
| 652 hqp_buckets.push_back(std::make_pair(0.0, 100)); | 652 {0.0, 100}, {1.0, 200}, {4.0, 500}, {8.0, 900}, {10.0, 1000}}; |
| 653 hqp_buckets.push_back(std::make_pair(1.0, 200)); | 653 base::AutoReset<ScoredHistoryMatch::ScoreMaxRelevances*> tmp( |
| 654 hqp_buckets.push_back(std::make_pair(4.0, 500)); | 654 &ScoredHistoryMatch::relevance_buckets_override_, &relevance_buckets); |
| 655 hqp_buckets.push_back(std::make_pair(8.0, 900)); | 655 |
| 656 hqp_buckets.push_back(std::make_pair(10.0, 1000)); | |
| 657 // Check when topicality score is zero. | 656 // Check when topicality score is zero. |
| 658 float topicality_score = 0.0; | 657 float topicality_score = 0.0; |
| 659 float frequency_score = 10.0; | 658 float frequency_score = 10.0; |
| 660 // intermediate_score = 0.0 * 10.0 = 0.0. | 659 // intermediate_score = 0.0 * 10.0 = 0.0. |
| 661 EXPECT_EQ(0, ScoredHistoryMatch::GetFinalRelevancyScore( | 660 EXPECT_EQ(0, ScoredHistoryMatch::GetFinalRelevancyScore(topicality_score, |
| 662 topicality_score, frequency_score, hqp_buckets)); | 661 frequency_score)); |
| 663 | 662 |
| 664 // Check when intermediate score falls at the border range. | 663 // Check when intermediate score falls at the border range. |
| 665 topicality_score = 0.4f; | 664 topicality_score = 0.4f; |
| 666 frequency_score = 10.0f; | 665 frequency_score = 10.0f; |
| 667 // intermediate_score = 0.5 * 10.0 = 4.0. | 666 // intermediate_score = 0.5 * 10.0 = 4.0. |
| 668 EXPECT_EQ(500, ScoredHistoryMatch::GetFinalRelevancyScore( | 667 EXPECT_EQ(500, ScoredHistoryMatch::GetFinalRelevancyScore(topicality_score, |
| 669 topicality_score, frequency_score, hqp_buckets)); | 668 frequency_score)); |
| 670 | 669 |
| 671 // Checking the score that falls into one of the buckets. | 670 // Checking the score that falls into one of the buckets. |
| 672 topicality_score = 0.5f; | 671 topicality_score = 0.5f; |
| 673 frequency_score = 10.0f; | 672 frequency_score = 10.0f; |
| 674 // intermediate_score = 0.5 * 10.0 = 5.0. | 673 // intermediate_score = 0.5 * 10.0 = 5.0. |
| 675 EXPECT_EQ(600, // 500 + (((900 - 500)/(8 -4)) * 1) = 600. | 674 EXPECT_EQ(600, // 500 + (((900 - 500)/(8 -4)) * 1) = 600. |
| 676 ScoredHistoryMatch::GetFinalRelevancyScore( | 675 ScoredHistoryMatch::GetFinalRelevancyScore(topicality_score, |
| 677 topicality_score, frequency_score, hqp_buckets)); | 676 frequency_score)); |
| 678 | 677 |
| 679 // Never give the score greater than maximum specified. | 678 // Never give the score greater than maximum specified. |
| 680 topicality_score = 0.5f; | 679 topicality_score = 0.5f; |
| 681 frequency_score = 22.0f; | 680 frequency_score = 22.0f; |
| 682 // intermediate_score = 0.5 * 22.0 = 11.0 | 681 // intermediate_score = 0.5 * 22.0 = 11.0 |
| 683 EXPECT_EQ(1000, ScoredHistoryMatch::GetFinalRelevancyScore( | 682 EXPECT_EQ(1000, ScoredHistoryMatch::GetFinalRelevancyScore(topicality_score, |
| 684 topicality_score, frequency_score, hqp_buckets)); | 683 frequency_score)); |
| 685 } | 684 } |
| 686 | 685 |
| 687 // Test the function GetHQPBucketsFromString(). | 686 // Test the function GetHQPBucketsFromString(). |
| 688 TEST_F(ScoredHistoryMatchTest, GetHQPBucketsFromString) { | 687 TEST_F(ScoredHistoryMatchTest, GetHQPBucketsFromString) { |
| 689 std::string buckets_str = "0.0:400,1.5:600,12.0:1300,20.0:1399"; | 688 std::string buckets_str = "0.0:400,1.5:600,12.0:1300,20.0:1399"; |
| 690 std::vector<ScoredHistoryMatch::ScoreMaxRelevance> hqp_buckets; | 689 std::vector<ScoredHistoryMatch::ScoreMaxRelevance> hqp_buckets = |
| 691 | 690 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str); |
| 692 EXPECT_TRUE( | |
| 693 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); | |
| 694 EXPECT_THAT(hqp_buckets, ElementsAre(Pair(0.0, 400), Pair(1.5, 600), | 691 EXPECT_THAT(hqp_buckets, ElementsAre(Pair(0.0, 400), Pair(1.5, 600), |
| 695 Pair(12.0, 1300), Pair(20.0, 1399))); | 692 Pair(12.0, 1300), Pair(20.0, 1399))); |
| 696 // invalid string. | 693 // Test using an invalid string. |
| 697 buckets_str = "0.0,400,1.5,600"; | 694 buckets_str = "0.0,400,1.5,600"; |
| 698 EXPECT_FALSE( | 695 hqp_buckets = ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str); |
| 699 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); | 696 EXPECT_TRUE(hqp_buckets.empty()); |
| 700 } | 697 } |
| OLD | NEW |