Пример #1
0
        public void TestRoulette3()
        {
            var populationcount = RouletteSelection <float, float> .IncludeTop;
            var samplecount     = 50000;

            var l = BufUtils.Populate <float>(() => BufUtils.RandomInt(2) == 0 ? 0f : BufUtils.RandomFloat(100000), populationcount);
            var r = new I2PCore.Utils.RouletteSelection <float, float>(l, v => v, k => k);

            int iszero = 0;

            for (int i = 0; i < samplecount; ++i)
            {
                if (r.GetWeightedRandom(null) < float.Epsilon)
                {
                    ++iszero;
                }
            }

            Assert.IsTrue(iszero > 0);
            Assert.IsTrue(iszero < samplecount / 2);
        }
Пример #2
0
        public void TestRoulette3()
        {
            var l = BufUtils.Populate <float>(() => BufUtils.RandomInt(2) == 0 ? 0f : BufUtils.RandomFloat(100000), 10000);
            var r = new I2PCore.Utils.RouletteSelection <float, float>(l, v => v, k => k, 2f);

            int iszero = 0;

            for (int i = 0; i < 10000; ++i)
            {
                if (r.GetWeightedRandom() == 0f)
                {
                    ++iszero;
                }
            }

            Assert.IsTrue(iszero > 10000 / 5);
            Assert.IsTrue(iszero < 10000 / 2);

            r = new I2PCore.Utils.RouletteSelection <float, float>(l, v => v, k => k, float.MaxValue);

            iszero = 0;
            for (int i = 0; i < 10000; ++i)
            {
                if (r.GetWeightedRandom() == 0f)
                {
                    ++iszero;
                }
            }

            Assert.IsTrue(iszero < 4);
        }