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

Side by Side Diff: chrome/browser/engagement/site_engagement_score_unittest.cc

Issue 2163233002: Allow rounding errors in Site Engagement tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | chrome/browser/engagement/site_engagement_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/engagement/site_engagement_score.h" 5 #include "chrome/browser/engagement/site_engagement_score.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/test/simple_test_clock.h" 10 #include "base/test/simple_test_clock.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/engagement/site_engagement_service.h" 12 #include "chrome/browser/engagement/site_engagement_service.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace { 15 namespace {
16 16
17 const int kLessAccumulationsThanNeededToMaxDailyEngagement = 2; 17 const int kLessAccumulationsThanNeededToMaxDailyEngagement = 2;
18 const int kMoreAccumulationsThanNeededToMaxDailyEngagement = 40; 18 const int kMoreAccumulationsThanNeededToMaxDailyEngagement = 40;
19 const int kMoreAccumulationsThanNeededToMaxTotalEngagement = 200; 19 const int kMoreAccumulationsThanNeededToMaxTotalEngagement = 200;
20 const int kLessDaysThanNeededToMaxTotalEngagement = 4; 20 const int kLessDaysThanNeededToMaxTotalEngagement = 4;
21 const int kMoreDaysThanNeededToMaxTotalEngagement = 40; 21 const int kMoreDaysThanNeededToMaxTotalEngagement = 40;
22 const int kLessPeriodsThanNeededToDecayMaxScore = 2; 22 const int kLessPeriodsThanNeededToDecayMaxScore = 2;
23 const int kMorePeriodsThanNeededToDecayMaxScore = 40; 23 const int kMorePeriodsThanNeededToDecayMaxScore = 40;
24 const double kMaxRoundingDeviation = 0.0001;
24 25
25 base::Time GetReferenceTime() { 26 base::Time GetReferenceTime() {
26 base::Time::Exploded exploded_reference_time; 27 base::Time::Exploded exploded_reference_time;
27 exploded_reference_time.year = 2015; 28 exploded_reference_time.year = 2015;
28 exploded_reference_time.month = 1; 29 exploded_reference_time.month = 1;
29 exploded_reference_time.day_of_month = 30; 30 exploded_reference_time.day_of_month = 30;
30 exploded_reference_time.day_of_week = 5; 31 exploded_reference_time.day_of_week = 5;
31 exploded_reference_time.hour = 11; 32 exploded_reference_time.hour = 11;
32 exploded_reference_time.minute = 0; 33 exploded_reference_time.minute = 0;
33 exploded_reference_time.second = 0; 34 exploded_reference_time.second = 0;
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 current_day += base::TimeDelta::FromDays(21); 437 current_day += base::TimeDelta::FromDays(21);
437 test_clock_.SetNow(current_day); 438 test_clock_.SetNow(current_day);
438 EXPECT_DOUBLE_EQ(2.0, score_.GetScore()); 439 EXPECT_DOUBLE_EQ(2.0, score_.GetScore());
439 440
440 // Ensure point removal happens after proportional decay. 441 // Ensure point removal happens after proportional decay.
441 score_.AddPoints(4.0); 442 score_.AddPoints(4.0);
442 EXPECT_DOUBLE_EQ(6.0, score_.GetScore()); 443 EXPECT_DOUBLE_EQ(6.0, score_.GetScore());
443 SetParamValue(SiteEngagementScore::DECAY_POINTS, 2.0); 444 SetParamValue(SiteEngagementScore::DECAY_POINTS, 2.0);
444 current_day += base::TimeDelta::FromDays(7); 445 current_day += base::TimeDelta::FromDays(7);
445 test_clock_.SetNow(current_day); 446 test_clock_.SetNow(current_day);
446 EXPECT_DOUBLE_EQ(1.0, score_.GetScore()); 447 EXPECT_NEAR(1.0, score_.GetScore(), kMaxRoundingDeviation);
447 } 448 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/engagement/site_engagement_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698