| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 TEST_F(FieldTrialTest, FiftyFiftyProbability) { | 93 TEST_F(FieldTrialTest, FiftyFiftyProbability) { |
| 94 // Check that even with small divisors, we have the proper probabilities, and | 94 // Check that even with small divisors, we have the proper probabilities, and |
| 95 // all outcomes are possible. Since this is a 50-50 test, it should get both | 95 // all outcomes are possible. Since this is a 50-50 test, it should get both |
| 96 // outcomes in a few tries, but we'll try no more than 100 times (and be flaky | 96 // outcomes in a few tries, but we'll try no more than 100 times (and be flaky |
| 97 // with probability around 1 in 2^99). | 97 // with probability around 1 in 2^99). |
| 98 bool first_winner = false; | 98 bool first_winner = false; |
| 99 bool second_winner = false; | 99 bool second_winner = false; |
| 100 int counter = 0; | 100 int counter = 0; |
| 101 do { | 101 do { |
| 102 std::string name = base::StringPrintf("FiftyFifty%d", ++counter); | 102 std::string name = base::StringPrintf("FiftyFifty%d", ++counter); |
| 103 scoped_refptr<FieldTrial> trial = new FieldTrial(name, 2); | 103 scoped_refptr<FieldTrial> trial(new FieldTrial(name, 2)); |
| 104 trial->AppendGroup("first", 1); // 50% chance of being chosen. | 104 trial->AppendGroup("first", 1); // 50% chance of being chosen. |
| 105 if (trial->group() != FieldTrial::kNotParticipating) { | 105 if (trial->group() != FieldTrial::kNotParticipating) { |
| 106 first_winner = true; | 106 first_winner = true; |
| 107 continue; | 107 continue; |
| 108 } | 108 } |
| 109 trial->AppendGroup("second", 1); // Always chosen at this point. | 109 trial->AppendGroup("second", 1); // Always chosen at this point. |
| 110 EXPECT_NE(FieldTrial::kNotParticipating, trial->group()); | 110 EXPECT_NE(FieldTrial::kNotParticipating, trial->group()); |
| 111 second_winner = true; | 111 second_winner = true; |
| 112 } while ((!second_winner || !first_winner) && counter < 100); | 112 } while ((!second_winner || !first_winner) && counter < 100); |
| 113 EXPECT_TRUE(second_winner); | 113 EXPECT_TRUE(second_winner); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 } | 224 } |
| 225 | 225 |
| 226 TEST_F(FieldTrialTest, MakeName) { | 226 TEST_F(FieldTrialTest, MakeName) { |
| 227 FieldTrial* trial = new FieldTrial("Field Trial", 10); | 227 FieldTrial* trial = new FieldTrial("Field Trial", 10); |
| 228 trial->AppendGroup("Winner", 10); | 228 trial->AppendGroup("Winner", 10); |
| 229 EXPECT_EQ("Histogram_Winner", | 229 EXPECT_EQ("Histogram_Winner", |
| 230 FieldTrial::MakeName("Histogram", "Field Trial")); | 230 FieldTrial::MakeName("Histogram", "Field Trial")); |
| 231 } | 231 } |
| 232 | 232 |
| 233 } // namespace base | 233 } // namespace base |
| OLD | NEW |