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); }
private void LogIn() { // set Response client.AddResponse(200, "{" + "\"id\" : \"user1234\"," + "\"access_token\" : \"cdef\"," + "\"expires_in\" : 9223372036854775}"); KiiUser.LogIn("kii1234", "pass1234"); }