Ejemplo n.º 1
0
        public void Create_NoInput_WeightsAreEqualToSpecification()
        {
            // Each outcome has a weighted probablity as described.
            // Apple - 10%, Mango - 15%, Cherry - 20%, Melon - 15%, Peach - 10%, Orange - 20%, Lemon - 10%

            WeightedSymbolCollectionFactory factory = new WeightedSymbolCollectionFactory();

            var symbols = factory.Create();

            WeightedSymbol apple  = symbols.Single(y => y.Name == "Apple");
            WeightedSymbol mango  = symbols.Single(y => y.Name == "Mango");
            WeightedSymbol cherry = symbols.Single(y => y.Name == "Cherry");
            WeightedSymbol melon  = symbols.Single(y => y.Name == "Melon");
            WeightedSymbol peach  = symbols.Single(y => y.Name == "Peach");
            WeightedSymbol orange = symbols.Single(y => y.Name == "Orange");
            WeightedSymbol lemon  = symbols.Single(y => y.Name == "Lemon");

            Assert.AreEqual(apple.Weight, 0.1);
            Assert.AreEqual(mango.Weight, 0.15);
            Assert.AreEqual(cherry.Weight, 0.2);
            Assert.AreEqual(melon.Weight, 0.15);
            Assert.AreEqual(peach.Weight, 0.1);
            Assert.AreEqual(orange.Weight, 0.2);
            Assert.AreEqual(lemon.Weight, 0.1);
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        public void Create_NoInput_Returns7Symbols()
        {
            // Create an ASP.Net Core Web API that simulates a spinning wheel that can land on 7 possible outcomes:

            WeightedSymbolCollectionFactory factory = new WeightedSymbolCollectionFactory();

            var symbols = factory.Create();

            Assert.IsTrue(symbols.Count() == 7);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public void Create_NoInput_ContainsAppleMangoCherryMelonPeachOrangeLemon()
        {
            // Create an ASP.Net Core Web API that simulates a spinning wheel that can land on 7 possible outcomes:
            // ["Apple", "Mango", "Cherry", "Melon", "Peach", "Orange", "Lemon"]

            WeightedSymbolCollectionFactory factory = new WeightedSymbolCollectionFactory();

            var symbols = factory.Create();

            Assert.IsTrue(symbols.Any(y => y.Name == "Apple"));
            Assert.IsTrue(symbols.Any(y => y.Name == "Mango"));
            Assert.IsTrue(symbols.Any(y => y.Name == "Cherry"));
            Assert.IsTrue(symbols.Any(y => y.Name == "Melon"));
            Assert.IsTrue(symbols.Any(y => y.Name == "Peach"));
            Assert.IsTrue(symbols.Any(y => y.Name == "Orange"));
            Assert.IsTrue(symbols.Any(y => y.Name == "Lemon"));
        }
 public RandomWeightedSymbolPickerController(RandomWeightedSymbolPicker randomWeightedSymbolPicker,
                                             WeightedSymbolCollectionFactory weightedSymbolCollectionFactory)
 {
     this.randomWeightedSymbolPicker      = randomWeightedSymbolPicker;
     this.weightedSymbolCollectionFactory = weightedSymbolCollectionFactory;
 }