示例#1
0
        public void Test_0000_OnCrank_Percentage_50_50()
        {
            System.Threading.Thread.Sleep(1);
            VariationSampler sampler = new RandomVariationSampler();

            client.AddResponse(200, CreateKiiExperimentAsJsonString(KiiExperimentStatus.RUNNING, 50, 50, null));
            KiiExperiment experiment     = KiiExperiment.GetByID("000001");
            Variation     variationA     = experiment.Variations[0]; // 50%
            Variation     variationB     = experiment.Variations[1]; // 50%
            int           selectedCountA = 0;
            int           selectedCountB = 0;

            for (int i = 0; i < 1000; i++)
            {
                System.Threading.Thread.Sleep(1);
                Variation variation = sampler.ChooseVariation(experiment, null);
                if (variation == variationA)
                {
                    selectedCountA++;
                }
                else if (variation == variationB)
                {
                    selectedCountB++;
                }
                else
                {
                    Assert.Fail("sampler returned unexpected variation");
                }
            }
            // This test will fail with a probability of 0.0017305361
            Assert.IsTrue(450 < selectedCountA, "selectedCountA=" + selectedCountA);
            Assert.IsTrue(550 > selectedCountA, "selectedCountA=" + selectedCountA);
            Assert.IsTrue(450 < selectedCountB, "selectedCountB=" + selectedCountB);
            Assert.IsTrue(550 > selectedCountB, "selectedCountB=" + selectedCountB);
        }
示例#2
0
        public void Test_0002_OnCrank_Percentage_0_100()
        {
            System.Threading.Thread.Sleep(1);
            VariationSampler sampler = new RandomVariationSampler();

            client.AddResponse(200, CreateKiiExperimentAsJsonString(KiiExperimentStatus.RUNNING, 0, 100, null));
            KiiExperiment experiment = KiiExperiment.GetByID("000001");
            Variation     variationA = experiment.Variations[0]; // 0%
            Variation     variationB = experiment.Variations[1]; // 100%
            bool          selectedA  = false;
            bool          selectedB  = false;

            for (int i = 0; i < 1000; i++)
            {
                System.Threading.Thread.Sleep(1);
                Variation variation = sampler.ChooseVariation(experiment, null);
                if (variation == variationA)
                {
                    selectedA = true;
                }
                else if (variation == variationB)
                {
                    selectedB = true;
                }
                else
                {
                    Assert.Fail("sampler returned unexpected variation");
                }
            }
            Assert.IsFalse(selectedA);
            Assert.IsTrue(selectedB);
        }
示例#3
0
        public void Test_0008_OnCrank_With_Status_TERMINATED_Whit_ChosenVariation()
        {
            System.Threading.Thread.Sleep(1);
            VariationSampler sampler = new RandomVariationSampler();

            client.AddResponse(200, CreateKiiExperimentAsJsonString(KiiExperimentStatus.TERMINATED, 50, 50, "B"));
            KiiExperiment experiment = KiiExperiment.GetByID("000001");
            Variation     variationA = experiment.Variations[0]; // 50%
            Variation     variationB = experiment.Variations[1]; // 50%

            Variation variation = sampler.ChooseVariation(experiment, null);

            Assert.AreEqual(variationB, variation);
            variation = sampler.ChooseVariation(experiment, variationA);
            Assert.AreEqual(variationB, variation);
            variation = sampler.ChooseVariation(experiment, variationB);
            Assert.AreEqual(variationB, variation);
        }