summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/field_trial.cc11
-rw-r--r--base/field_trial.h8
-rw-r--r--base/field_trial_unittest.cc21
3 files changed, 33 insertions, 7 deletions
diff --git a/base/field_trial.cc b/base/field_trial.cc
index 549822f..2b354d7 100644
--- a/base/field_trial.cc
+++ b/base/field_trial.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -36,10 +36,15 @@ FieldTrial::FieldTrial(const std::string& name,
int FieldTrial::AppendGroup(const std::string& name,
Probability group_probability) {
DCHECK(group_probability <= divisor_);
- accumulated_group_probability_ += group_probability;
+ DCHECK(group_probability >=0 ||
+ group_probability == kAllRemainingProbability);
+ if (group_probability == kAllRemainingProbability)
+ accumulated_group_probability_ = divisor_;
+ else
+ accumulated_group_probability_ += group_probability;
DCHECK(accumulated_group_probability_ <= divisor_);
if (group_ == kNotParticipating && accumulated_group_probability_ > random_) {
- // This is the group that crossed the random line, so we do teh assignment.
+ // This is the group that crossed the random line, so we do the assignment.
group_ = next_group_number_;
if (name.empty())
StringAppendF(&group_name_, "_%d", group_);
diff --git a/base/field_trial.h b/base/field_trial.h
index 6d3c101..fba0b01 100644
--- a/base/field_trial.h
+++ b/base/field_trial.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -50,7 +50,7 @@
// "MemoryExperiment").data(), count);
// The above code will create 3 distinct histograms, with each run of the
-// application being assigned to of of teh three groups, and for each group, the
+// application being assigned to of of the three groups, and for each group, the
// correspondingly named histogram will be populated:
// Memory.RendererTotal // 96% of users still fill this histogram.
@@ -80,7 +80,9 @@ class FieldTrial : public base::RefCounted<FieldTrial> {
// Provide an easy way to assign all remaining probability to a group. Note
// that this will force an instance to participate, and make it illegal to
- // attempt to probabalistically add any other groups to the trial.
+ // attempt to probabalistically add any other groups to the trial. When doing
+ // A/B tests with timings, it is often best to define all groups, so that
+ // histograms will get unique names via the MakeName() methods.
static const Probability kAllRemainingProbability;
// The name is used to register the instance with the FieldTrialList class,
diff --git a/base/field_trial_unittest.cc b/base/field_trial_unittest.cc
index 59d8e15..430fd67 100644
--- a/base/field_trial_unittest.cc
+++ b/base/field_trial_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -69,6 +69,25 @@ TEST_F(FieldTrialTest, AbsoluteProbabilities) {
}
}
+TEST_F(FieldTrialTest, RemainingProbability) {
+ // First create a test that hasn't had a winner yet.
+ const std::string winner = "Winner";
+ const std::string loser = "Loser";
+ scoped_refptr<FieldTrial> trial;
+ int counter = 0;
+ do {
+ std::string name = StringPrintf("trial%d", ++counter);
+ trial = new FieldTrial(name, 10);
+ trial->AppendGroup(loser, 5); // 50% chance of not being chosen.
+ } while (trial->group() != FieldTrial::kNotParticipating);
+
+ // Now add a winner with all remaining probability.
+ trial->AppendGroup(winner, FieldTrial::kAllRemainingProbability);
+
+ // And that winner should ALWAYS win.
+ EXPECT_EQ(winner, trial->group_name());
+}
+
TEST_F(FieldTrialTest, MiddleProbabilities) {
char name[] = " same name";
bool false_event_seen = false;