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); } }
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); }
private TreeNodeTraits(WeightedSymbol symbol) { Symbol = symbol; }