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 base::AutoReset<std::vector<ScoredHistoryMatch::ScoreMaxRelevance>> tmp( |
652 hqp_buckets.push_back(std::make_pair(0.0, 100)); | 652 ScoredHistoryMatch::relevance_buckets_, |
653 hqp_buckets.push_back(std::make_pair(1.0, 200)); | 653 std::vector<ScoredHistoryMatch::ScoreMaxRelevance>()); |
654 hqp_buckets.push_back(std::make_pair(4.0, 500)); | 654 ScoredHistoryMatch::relevance_buckets_->push_back(std::make_pair(0.0, 100)); |
655 hqp_buckets.push_back(std::make_pair(8.0, 900)); | 655 ScoredHistoryMatch::relevance_buckets_->push_back(std::make_pair(1.0, 200)); |
656 hqp_buckets.push_back(std::make_pair(10.0, 1000)); | 656 ScoredHistoryMatch::relevance_buckets_->push_back(std::make_pair(4.0, 500)); |
657 ScoredHistoryMatch::relevance_buckets_->push_back(std::make_pair(8.0, 900)); | |
658 ScoredHistoryMatch::relevance_buckets_->push_back(std::make_pair(10.0, 1000)); | |
Peter Kasting
2016/12/08 01:29:22
Can you do something like this to avoid all the pu
Mark P
2016/12/09 20:40:56
Done.
| |
659 | |
657 // Check when topicality score is zero. | 660 // Check when topicality score is zero. |
658 float topicality_score = 0.0; | 661 float topicality_score = 0.0; |
659 float frequency_score = 10.0; | 662 float frequency_score = 10.0; |
660 // intermediate_score = 0.0 * 10.0 = 0.0. | 663 // intermediate_score = 0.0 * 10.0 = 0.0. |
661 EXPECT_EQ(0, ScoredHistoryMatch::GetFinalRelevancyScore( | 664 EXPECT_EQ(0, ScoredHistoryMatch::GetFinalRelevancyScore(topicality_score, |
662 topicality_score, frequency_score, hqp_buckets)); | 665 frequency_score)); |
663 | 666 |
664 // Check when intermediate score falls at the border range. | 667 // Check when intermediate score falls at the border range. |
665 topicality_score = 0.4f; | 668 topicality_score = 0.4f; |
666 frequency_score = 10.0f; | 669 frequency_score = 10.0f; |
667 // intermediate_score = 0.5 * 10.0 = 4.0. | 670 // intermediate_score = 0.5 * 10.0 = 4.0. |
668 EXPECT_EQ(500, ScoredHistoryMatch::GetFinalRelevancyScore( | 671 EXPECT_EQ(500, ScoredHistoryMatch::GetFinalRelevancyScore(topicality_score, |
669 topicality_score, frequency_score, hqp_buckets)); | 672 frequency_score)); |
670 | 673 |
671 // Checking the score that falls into one of the buckets. | 674 // Checking the score that falls into one of the buckets. |
672 topicality_score = 0.5f; | 675 topicality_score = 0.5f; |
673 frequency_score = 10.0f; | 676 frequency_score = 10.0f; |
674 // intermediate_score = 0.5 * 10.0 = 5.0. | 677 // intermediate_score = 0.5 * 10.0 = 5.0. |
675 EXPECT_EQ(600, // 500 + (((900 - 500)/(8 -4)) * 1) = 600. | 678 EXPECT_EQ(600, // 500 + (((900 - 500)/(8 -4)) * 1) = 600. |
676 ScoredHistoryMatch::GetFinalRelevancyScore( | 679 ScoredHistoryMatch::GetFinalRelevancyScore(topicality_score, |
677 topicality_score, frequency_score, hqp_buckets)); | 680 frequency_score)); |
678 | 681 |
679 // Never give the score greater than maximum specified. | 682 // Never give the score greater than maximum specified. |
680 topicality_score = 0.5f; | 683 topicality_score = 0.5f; |
681 frequency_score = 22.0f; | 684 frequency_score = 22.0f; |
682 // intermediate_score = 0.5 * 22.0 = 11.0 | 685 // intermediate_score = 0.5 * 22.0 = 11.0 |
683 EXPECT_EQ(1000, ScoredHistoryMatch::GetFinalRelevancyScore( | 686 EXPECT_EQ(1000, ScoredHistoryMatch::GetFinalRelevancyScore(topicality_score, |
684 topicality_score, frequency_score, hqp_buckets)); | 687 frequency_score)); |
685 } | 688 } |
686 | 689 |
687 // Test the function GetHQPBucketsFromString(). | 690 // Test the function GetHQPBucketsFromString(). |
688 TEST_F(ScoredHistoryMatchTest, GetHQPBucketsFromString) { | 691 TEST_F(ScoredHistoryMatchTest, GetHQPBucketsFromString) { |
689 std::string buckets_str = "0.0:400,1.5:600,12.0:1300,20.0:1399"; | 692 std::string buckets_str = "0.0:400,1.5:600,12.0:1300,20.0:1399"; |
690 std::vector<ScoredHistoryMatch::ScoreMaxRelevance> hqp_buckets; | 693 std::vector<ScoredHistoryMatch::ScoreMaxRelevance> hqp_buckets = |
691 | 694 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), | 695 EXPECT_THAT(hqp_buckets, ElementsAre(Pair(0.0, 400), Pair(1.5, 600), |
695 Pair(12.0, 1300), Pair(20.0, 1399))); | 696 Pair(12.0, 1300), Pair(20.0, 1399))); |
696 // invalid string. | 697 // Test using an invalid string. |
697 buckets_str = "0.0,400,1.5,600"; | 698 buckets_str = "0.0,400,1.5,600"; |
698 EXPECT_FALSE( | 699 hqp_buckets = ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str); |
699 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); | 700 EXPECT_TRUE(hqp_buckets.empty()); |
700 } | 701 } |
OLD | NEW |