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

Side by Side Diff: base/field_trial_unittest.cc

Issue 150141: Implement shortcut for finalizing a trial with all remaining probability... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « base/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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 // Test of FieldTrial class 5 // Test of FieldTrial class
6 6
7 #include "base/field_trial.h" 7 #include "base/field_trial.h"
8 8
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 EXPECT_EQ(trial_true->group(), winner_group); 62 EXPECT_EQ(trial_true->group(), winner_group);
63 EXPECT_EQ(trial_true->group_name(), winner); 63 EXPECT_EQ(trial_true->group_name(), winner);
64 64
65 FieldTrial* trial_false = new FieldTrial(always_false, 10); 65 FieldTrial* trial_false = new FieldTrial(always_false, 10);
66 int loser_group = trial_false->AppendGroup("ALoser", 0); 66 int loser_group = trial_false->AppendGroup("ALoser", 0);
67 67
68 EXPECT_NE(trial_false->group(), loser_group); 68 EXPECT_NE(trial_false->group(), loser_group);
69 } 69 }
70 } 70 }
71 71
72 TEST_F(FieldTrialTest, RemainingProbability) {
73 // First create a test that hasn't had a winner yet.
74 const std::string winner = "Winner";
75 const std::string loser = "Loser";
76 scoped_refptr<FieldTrial> trial;
77 int counter = 0;
78 do {
79 std::string name = StringPrintf("trial%d", ++counter);
80 trial = new FieldTrial(name, 10);
81 trial->AppendGroup(loser, 5); // 50% chance of not being chosen.
82 } while (trial->group() != FieldTrial::kNotParticipating);
83
84 // Now add a winner with all remaining probability.
85 trial->AppendGroup(winner, FieldTrial::kAllRemainingProbability);
86
87 // And that winner should ALWAYS win.
88 EXPECT_EQ(winner, trial->group_name());
89 }
90
72 TEST_F(FieldTrialTest, MiddleProbabilities) { 91 TEST_F(FieldTrialTest, MiddleProbabilities) {
73 char name[] = " same name"; 92 char name[] = " same name";
74 bool false_event_seen = false; 93 bool false_event_seen = false;
75 bool true_event_seen = false; 94 bool true_event_seen = false;
76 for (int i = 1; i < 250; ++i) { 95 for (int i = 1; i < 250; ++i) {
77 name[0] = i; 96 name[0] = i;
78 FieldTrial* trial = new FieldTrial(name, 10); 97 FieldTrial* trial = new FieldTrial(name, 10);
79 int might_win = trial->AppendGroup("MightWin", 5); 98 int might_win = trial->AppendGroup("MightWin", 5);
80 99
81 if (trial->group() == might_win) { 100 if (trial->group() == might_win) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 std::string save_string; 189 std::string save_string;
171 FieldTrialList::StatesToString(&save_string); 190 FieldTrialList::StatesToString(&save_string);
172 EXPECT_EQ("Some name/Winner/", save_string); 191 EXPECT_EQ("Some name/Winner/", save_string);
173 192
174 // It is OK if we redundantly specify a winner. 193 // It is OK if we redundantly specify a winner.
175 EXPECT_TRUE(FieldTrialList::StringAugmentsState(save_string)); 194 EXPECT_TRUE(FieldTrialList::StringAugmentsState(save_string));
176 195
177 // But it is an error to try to change to a different winner. 196 // But it is an error to try to change to a different winner.
178 EXPECT_FALSE(FieldTrialList::StringAugmentsState("Some name/Loser/")); 197 EXPECT_FALSE(FieldTrialList::StringAugmentsState("Some name/Loser/"));
179 } 198 }
OLDNEW
« no previous file with comments | « base/field_trial.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698