Пример #1
0
        public void UnitTests()
        {
            var fixedRandom = new FixedRandom();

            var test        = new WeightedRandom(fixedRandom);
            var w1          = new Weight(1.0f);
            var w2          = new Weight(0.5f);
            var w3          = new Weight(0.25f);
            var totalWeight = w1.Value + w2.Value + w3.Value;

            test.Add(w1);
            test.Add(w2);
            test.Add(w3);

            Assert.AreEqual(w1, test.ChooseFactor(.5f / totalWeight));
            Assert.AreEqual(w1, test.ChooseFactor(.9f / totalWeight));
            Assert.AreEqual(w2, test.ChooseFactor(1.1f / totalWeight));
            Assert.AreEqual(w3, test.ChooseFactor(1.6f / totalWeight));
        }