public void Win1Randomness_IsApproximatelyConvergentToExpectation() { const DiceValue selectedFace = DiceValue.SPADE; const int numDice = 3; const int numThrows = 10000; var hitCount = 0d; var die = new Dice(); for (var i = 0; i <= numThrows; i++) { var hit = false; var rollCount = 0; for (var j = 0; j < numDice; j++) { die.roll(); if (die.CurrentValue == selectedFace) rollCount++; } if (rollCount == 1) hitCount++; } hitCount.Should() .BeGreaterThan(34) .And.BeLessThan(35, " P(X=1)=P (first dice match) +P(second dice match) +P(third dice match) =1/6 . 5/6 . 5/6 + 5/6 . 1/6 . 5/6 + 5/6 . 5/6 . 1/6 = 25/72 = 0.3472 And Should converge to:- 100 * 0.3472"); }
public void TestRoll() { Dictionary<DiceValue, int> countMap = new Dictionary<DiceValue, int>() { { DiceValue.CROWN,0}, { DiceValue.ANCHOR,0}, { DiceValue.HEART,0}, { DiceValue.DIAMOND,0}, { DiceValue.CLUB,0}, { DiceValue.SPADE,0}, }; Dice d1 = new Dice(); for (int i = 0; i < 100; i++) { d1.roll(); countMap[d1.CurrentValue] += 1; } foreach (DiceValue dv in Enum.GetValues(typeof(DiceValue))) { if (countMap[dv] == 0) { Assert.Fail("random didn't generate all values"); } } }
public void TestGameDiceRandomness() { var dice = new Dice(); var values = new List<DiceValue>(); for (var i = 0; i < 100; i++) { values.Add(dice.roll()); } Console.WriteLine(string.Join(",", values.Distinct())); values.Distinct().Count().Should().Be(6); }
public void WhenDiceRolledValueShouldReflectNewRoll() { var die1 = new Dice(); var die2 = new Dice(); var die3 = new Dice(); int bet = 5; int winCount = 0; int loseCount = 0; var pick = Dice.RandomValue; var player = new Player("Test", 100); var game = new Game(die1, die2, die3); game.playRound(player, pick, bet); var newDie1Value = die1.roll(); var newDie2Value = die2.roll(); var newDie3Value = die3.roll(); Assert.Equal(die1.CurrentValue, game.CurrentDiceValues[0]); Assert.Equal(die2.CurrentValue, game.CurrentDiceValues[1]); Assert.Equal(die3.CurrentValue, game.CurrentDiceValues[2]); Assert.Equal(newDie1Value, die1.CurrentValue); Assert.Equal(newDie2Value, die2.CurrentValue); Assert.Equal(newDie3Value, die3.CurrentValue); }