Esempio n. 1
0
        public void Pick_WeightedSymbolCollectionFactory_RandomPicksMatchesWeightDistribution(int tries)
        {
            RandomWeightedSymbolPicker      randomWeightedSymbolPicker      = new RandomWeightedSymbolPicker();
            WeightedSymbolCollectionFactory weightedSymbolCollectionFactory = new WeightedSymbolCollectionFactory();

            IEnumerable <WeightedSymbol> weightedSymbols = weightedSymbolCollectionFactory.Create();
            List <WeightedSymbol>        picks           = randomWeightedSymbolPicker.Pick(weightedSymbols, tries).ToList();

            var picksSymbolGroup = picks.GroupBy(y => y);

            foreach (var symbolGroup in picksSymbolGroup)
            {
                WeightedSymbol weightedSymbol   = symbolGroup.Key;
                int            symbolGroupCount = symbolGroup.Count();

                // What is the calculated weight of the symbol we actually picked with the random picker?
                double avgPickWeight = symbolGroupCount / (double)tries;

                // What is the actual predefined weight?
                double wsWeight = symbolGroup.Key.Weight;

                const double similarPcnt = 0.01;

                // The weights should be very similar. Let's say 1% similar.
                double wsWeightMin = wsWeight - wsWeight * similarPcnt;
                double wsWeightMax = wsWeight + wsWeight * similarPcnt;

                Assert.IsTrue(avgPickWeight >= wsWeightMin);
                Assert.IsTrue(avgPickWeight <= wsWeightMax);
            }
        }
Esempio n. 2
0
        public void Pick_WeightedSymbolCollectionFactory_ResultCountMatchesTries(int tries)
        {
            RandomWeightedSymbolPicker      randomWeightedSymbolPicker      = new RandomWeightedSymbolPicker();
            WeightedSymbolCollectionFactory weightedSymbolCollectionFactory = new WeightedSymbolCollectionFactory();

            IEnumerable <WeightedSymbol> weightedSymbols = weightedSymbolCollectionFactory.Create();
            List <WeightedSymbol>        picks           = randomWeightedSymbolPicker.Pick(weightedSymbols, tries).ToList();

            Assert.AreEqual(picks.Count, tries);
        }
 public RandomWeightedSymbolPickerController(RandomWeightedSymbolPicker randomWeightedSymbolPicker,
                                             WeightedSymbolCollectionFactory weightedSymbolCollectionFactory)
 {
     this.randomWeightedSymbolPicker      = randomWeightedSymbolPicker;
     this.weightedSymbolCollectionFactory = weightedSymbolCollectionFactory;
 }