public void SelectTest([Values(-0.1f, 0.0f, 0.1f, 0.5f, 0.9f, 1.0f, 2.0f)] float proportion)
        {
            var cP     = proportion.Clamp01();
            var rn     = new MockRandom();
            var rnList = new List <double>();

            for (int i = 0; i < 100; i++)
            {
                rnList.Add(_rnd.NextDouble());
            }

            rn.Values = rnList;
            var s = new WeightedRandomSelector(rn);

            s.Proportion = proportion;

            var uList  = SelectorTestsHelper.CreateRandomUtilityList(20);
            var sorted = uList.OrderByDescending(x => x.Combined).ToList();

            for (int curI = 0; curI < 100; curI++)
            {
                Utility cUtil = CorrectUtility(curI, cP, uList, sorted, rnList);

                var aIdx  = s.Select(uList);
                var aUtil = new Utility(0.0f, 0.0f);
                if (aIdx >= 0)
                {
                    aUtil = uList[aIdx];
                }

                Assert.That(aUtil.Value, Is.EqualTo(cUtil.Value).Within(Tolerance));
                Assert.That(aUtil.Weight, Is.EqualTo(cUtil.Weight).Within(Tolerance));
            }
        }
示例#2
0
        public void SelectTest()
        {
            var size = 20;
            var s    = new MaxUtilitySelector();

            for (int i = 0; i < 100; i++)
            {
                var list = SelectorTestsHelper.CreateRandomUtilityList(size);
                var aVal = s.Select(list);
                var cVal = MaxUtilityIndex(list);
                Assert.AreEqual(cVal, aVal);
            }
        }
        public void SelectTest1()
        {
            var size = 20;
            var s    = new SequentialSelector();
            var list = SelectorTestsHelper.CreateRandomUtilityList(size);

            for (int i = 0; i < 1000; i++)
            {
                var aVal = s.Select(list);
                var cVal = i % size;
                Assert.AreEqual(cVal, aVal);
            }
        }
示例#4
0
        public void SelectTest([Range(-1, 21, 1)] int selIdx)
        {
            var rn = new MockRandom();

            rn.IntValue = selIdx;
            var uList = SelectorTestsHelper.CreateRandomUtilityList(20);
            var s     = new RandomSelector(rn);

            var aIdx = s.Select(uList);
            var cIdx = selIdx.Clamp(0, 19);

            Assert.That(aIdx, Is.EqualTo(cIdx));
        }