Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
| 8 | 8 |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 winner_index = might_win; | 153 winner_index = might_win; |
| 154 StringAppendF(&winner_name, "%d", might_win); | 154 StringAppendF(&winner_name, "%d", might_win); |
| 155 EXPECT_EQ(winner_name, trial->group_name()); | 155 EXPECT_EQ(winner_name, trial->group_name()); |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 EXPECT_GE(winner_index, 0); | 158 EXPECT_GE(winner_index, 0); |
| 159 EXPECT_EQ(trial->group(), winner_index); | 159 EXPECT_EQ(trial->group(), winner_index); |
| 160 EXPECT_EQ(trial->group_name(), winner_name); | 160 EXPECT_EQ(trial->group_name(), winner_name); |
| 161 } | 161 } |
| 162 | 162 |
| 163 TEST_F(FieldTrialTest, DisableProbability) { | |
| 164 // First create a test that hasn't had a winner yet. | |
| 165 const std::string winner = "Winner"; | |
| 166 const std::string loser = "Loser"; | |
| 167 scoped_refptr<FieldTrial> trial; | |
| 168 std::string name = StringPrintf("trial"); | |
| 169 trial = new FieldTrial(name, 1000000000); | |
| 170 trial->SetDisableDuration(base::TimeDelta::FromDays(-1)); | |
| 171 trial->AppendGroup(loser, 999999999); // 99.9999999% chance of being chosen. | |
| 172 // Now add a winner with all remaining probability. | |
| 173 trial->AppendGroup(winner, FieldTrial::kAllRemainingProbability); | |
| 174 | |
| 175 // And that winner should ALWAYS win. | |
| 176 EXPECT_EQ(winner, trial->group_name()); | |
| 177 EXPECT_EQ(winner, trial->group_name()); | |
|
jar (doing other things)
2011/01/10 22:03:18
Why is this line repeated? What was intended?
rtenneti
2011/01/10 22:48:03
Done.
| |
| 178 } | |
| 179 | |
| 163 TEST_F(FieldTrialTest, Save) { | 180 TEST_F(FieldTrialTest, Save) { |
| 164 std::string save_string; | 181 std::string save_string; |
| 165 | 182 |
| 166 FieldTrial* trial = new FieldTrial("Some name", 10); | 183 FieldTrial* trial = new FieldTrial("Some name", 10); |
| 167 // There is no winner yet, so no textual group name is associated with trial. | 184 // There is no winner yet, so no textual group name is associated with trial. |
| 168 EXPECT_EQ("", trial->group_name()); | 185 EXPECT_EQ("", trial->group_name()); |
| 169 FieldTrialList::StatesToString(&save_string); | 186 FieldTrialList::StatesToString(&save_string); |
| 170 EXPECT_EQ("", save_string); | 187 EXPECT_EQ("", save_string); |
| 171 save_string.clear(); | 188 save_string.clear(); |
| 172 | 189 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 } | 241 } |
| 225 | 242 |
| 226 TEST_F(FieldTrialTest, MakeName) { | 243 TEST_F(FieldTrialTest, MakeName) { |
| 227 FieldTrial* trial = new FieldTrial("Field Trial", 10); | 244 FieldTrial* trial = new FieldTrial("Field Trial", 10); |
| 228 trial->AppendGroup("Winner", 10); | 245 trial->AppendGroup("Winner", 10); |
| 229 EXPECT_EQ("Histogram_Winner", | 246 EXPECT_EQ("Histogram_Winner", |
| 230 FieldTrial::MakeName("Histogram", "Field Trial")); | 247 FieldTrial::MakeName("Histogram", "Field Trial")); |
| 231 } | 248 } |
| 232 | 249 |
| 233 } // namespace base | 250 } // namespace base |
| OLD | NEW |