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

Side by Side Diff: base/metrics/field_trial_unittest.cc

Issue 23710041: Fix inconsistent FieldTrial group assignment due to float errors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 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
« no previous file with comments | « base/metrics/field_trial.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/metrics/field_trial.h" 5 #include "base/metrics/field_trial.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 const char kGroupName[] = "Group2"; 842 const char kGroupName[] = "Group2";
843 const int kProbability = 100; 843 const int kProbability = 100;
844 ASSERT_FALSE(FieldTrialList::TrialExists(kTrialName)); 844 ASSERT_FALSE(FieldTrialList::TrialExists(kTrialName));
845 845
846 FieldTrial* trial = 846 FieldTrial* trial =
847 CreateFieldTrial(kTrialName, kProbability, kDefaultGroupName, NULL); 847 CreateFieldTrial(kTrialName, kProbability, kDefaultGroupName, NULL);
848 trial->AppendGroup(kGroupName, kProbability); 848 trial->AppendGroup(kGroupName, kProbability);
849 EXPECT_EQ(kGroupName, trial->group_name()); 849 EXPECT_EQ(kGroupName, trial->group_name());
850 } 850 }
851 851
852 TEST_F(FieldTrialTest, FloatBoundariesGiveEqualGroupSizes) {
853 const int kBucketCount = 100;
854
855 // Try each boundary value |i / 100.0| as the entropy value.
856 for (int i = 0; i < kBucketCount; ++i) {
857 const double entropy = i / static_cast<double>(kBucketCount);
858
859 scoped_refptr<base::FieldTrial> trial(
860 new base::FieldTrial("test", kBucketCount, "default", entropy));
861 for (int j = 0; j < kBucketCount; ++j)
862 trial->AppendGroup(base::StringPrintf("%d", j), 1);
863
864 EXPECT_EQ(base::StringPrintf("%d", i), trial->group_name());
865 }
866 }
867
868 TEST_F(FieldTrialTest, DoesNotSurpassTotalProbability) {
869 const double kEntropyValue = 1.0 - 1e-9;
870 ASSERT_LT(kEntropyValue, 1.0);
871
872 scoped_refptr<base::FieldTrial> trial(
873 new base::FieldTrial("test", 2, "default", kEntropyValue));
874 trial->AppendGroup("1", 1);
875 trial->AppendGroup("2", 1);
876
877 EXPECT_EQ("2", trial->group_name());
878 }
879
852 } // namespace base 880 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/field_trial.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698