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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/metrics/field_trial.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/field_trial_unittest.cc
===================================================================
--- base/metrics/field_trial_unittest.cc (revision 223657)
+++ base/metrics/field_trial_unittest.cc (working copy)
@@ -849,4 +849,32 @@
EXPECT_EQ(kGroupName, trial->group_name());
}
+TEST_F(FieldTrialTest, FloatBoundariesGiveEqualGroupSizes) {
+ const int kBucketCount = 100;
+
+ // Try each boundary value |i / 100.0| as the entropy value.
+ for (int i = 0; i < kBucketCount; ++i) {
+ const double entropy = i / static_cast<double>(kBucketCount);
+
+ scoped_refptr<base::FieldTrial> trial(
+ new base::FieldTrial("test", kBucketCount, "default", entropy));
+ for (int j = 0; j < kBucketCount; ++j)
+ trial->AppendGroup(base::StringPrintf("%d", j), 1);
+
+ EXPECT_EQ(base::StringPrintf("%d", i), trial->group_name());
+ }
+}
+
+TEST_F(FieldTrialTest, DoesNotSurpassTotalProbability) {
+ const double kEntropyValue = 1.0 - 1e-9;
+ ASSERT_LT(kEntropyValue, 1.0);
+
+ scoped_refptr<base::FieldTrial> trial(
+ new base::FieldTrial("test", 2, "default", kEntropyValue));
+ trial->AppendGroup("1", 1);
+ trial->AppendGroup("2", 1);
+
+ EXPECT_EQ("2", trial->group_name());
+}
+
} // namespace base
« 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