Пример #1
0
        public void IsInVariant_IsEquallyDistributed(int numberOfUsers, int experimentId)
        {
            var service = new ExperimentService();

            var userIds = Enumerable.Range(0, numberOfUsers).Select(x => x.ToString());
            int control = 0;
            int variant = 0;

            foreach (var userId in userIds)
            {
                var isInVariant = service.IsInVariant(experimentId, userId);
                if (isInVariant)
                {
                    variant++;
                }
                else
                {
                    control++;
                }
            }

            var diff       = (double)variant - control;
            var percentage = Math.Abs((diff / control) * 100);

            Assert.True(percentage < 0.5, $"Control: {control}\tVariant:{variant}\tPercentage{percentage}\tExperimentId:{experimentId}");
        }
Пример #2
0
        public void IsInVariant_ReturnsSameValueForEachInvocation(int experimentId, int userId)
        {
            var iterations = 1000;
            var service    = new ExperimentService();

            var control = 0;
            var variant = 0;

            for (var i = 0; i < iterations; i++)
            {
                var isInVariant = service.IsInVariant(experimentId, userId.ToString());
                if (isInVariant)
                {
                    variant++;
                }
                else
                {
                    control++;
                }
            }

            Assert.False(control > 0 && variant > 0, $"Control: {control}\tVariant: {variant}\tExperimentID: {experimentId}\tUserID: {userId}");
        }
Пример #3
0
        public void IsInVariant_GivesUsersBothVariants(int userId, List <int> experimentIds)
        {
            var service = new ExperimentService();

            var control = 0;
            var variant = 0;

            foreach (var id in experimentIds)
            {
                var isInVariant = service.IsInVariant(id, userId.ToString());
                if (isInVariant)
                {
                    variant++;
                }
                else
                {
                    control++;
                }
            }

            var minimumParticipations = (int)(experimentIds.Count * 0.45);

            Assert.True(control > minimumParticipations && variant > minimumParticipations, $"Control: {control}\tVariant: {variant}\tUserID: {userId}");
        }