public void Test_0000_OnCrank_Percentage_50_50()
 {
     this.LogIn();
     VariationSampler sampler = new VariationSamplerByKiiUser();
     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++)
     {
         this.LogIn();
         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);
 }
 public void Test_0001_OnCrank_Percentage_100_0()
 {
     this.LogIn();
     VariationSampler sampler = new VariationSamplerByKiiUser();
     client.AddResponse(200, CreateKiiExperimentAsJsonString(KiiExperimentStatus.RUNNING, 100, 0, null));
     KiiExperiment experiment = KiiExperiment.GetByID("000001");
     Variation variationA = experiment.Variations[0]; // 100%
     Variation variationB = experiment.Variations[1]; // 0%
     bool selectedA = false;
     bool selectedB = false;
     for (int i = 0; i < 1000; i++)
     {
         this.LogIn();
         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.IsTrue(selectedA);
     Assert.IsFalse(selectedB);
 }
        public void Test_0008_OnCrank_With_Status_TERMINATED_Whit_ChosenVariation()
        {
            this.LogIn();
            VariationSampler sampler = new VariationSamplerByKiiUser();
            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);
        }