diff options
author | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-12 23:17:04 +0000 |
---|---|---|
committer | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-12 23:17:04 +0000 |
commit | 5a715757b21fea252dc5889103650153f04b0822 (patch) | |
tree | b9bbdd6dbc64015225ed37e14a604589821e0554 /base | |
parent | 5b8466a17b02a144fe83ddfcaa09237636505030 (diff) | |
download | chromium_src-5a715757b21fea252dc5889103650153f04b0822.zip chromium_src-5a715757b21fea252dc5889103650153f04b0822.tar.gz chromium_src-5a715757b21fea252dc5889103650153f04b0822.tar.bz2 |
Add extra unit test to avoid off-by-one errors
I was worried about this problem, and realized I didn't
have a unit test to ensure the correctness in this
case. This just adds a unit test.
r=rvargas
Review URL: http://codereview.chromium.org/3535009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62354 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/field_trial_unittest.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/base/field_trial_unittest.cc b/base/field_trial_unittest.cc index 54523dd..94eb7fc 100644 --- a/base/field_trial_unittest.cc +++ b/base/field_trial_unittest.cc @@ -88,6 +88,30 @@ TEST_F(FieldTrialTest, RemainingProbability) { EXPECT_EQ(winner, trial->group_name()); } +TEST_F(FieldTrialTest, FiftyFiftyProbability) { + // Check that even with small divisors, we have the proper probabilities, and + // all outcomes are possible. Since this is a 50-50 test, it should get both + // outcomes in a few tries, but we'll try no more than 100 times (and be flaky + // with probability around 1 in 2^99). + bool first_winner = false; + bool second_winner = false; + int counter = 0; + do { + std::string name = base::StringPrintf("FiftyFifty%d", ++counter); + scoped_refptr<FieldTrial> trial = new FieldTrial(name, 2); + trial->AppendGroup("first", 1); // 50% chance of being chosen. + if (trial->group() != FieldTrial::kNotParticipating) { + first_winner = true; + continue; + } + trial->AppendGroup("second", 1); // Always chosen at this point. + EXPECT_NE(FieldTrial::kNotParticipating, trial->group()); + second_winner = true; + } while ((!second_winner || !first_winner) && counter < 100); + EXPECT_TRUE(second_winner); + EXPECT_TRUE(first_winner); +} + TEST_F(FieldTrialTest, MiddleProbabilities) { char name[] = " same name"; bool false_event_seen = false; |