Skip to content

Commit

Permalink
Merge pull request #204 from rkdarst/python-yahtzee
Browse files Browse the repository at this point in the history
yahtzee_sol: Test against a distribution
  • Loading branch information
rkdarst authored Aug 23, 2023
2 parents 3278ee3 + 8b5a7ce commit 7d8b830
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions content/code/python/yahtzee_sol.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ def test_roll_dice():
assert roll_dice(5) == [5, 2, 5, 2, 3]


import pytest
def test_yahtzee():
random.seed(1)
num_games = 10000
n_tests = 1_000_000

winning_games = list(
filter(
lambda x: x == 5,
[yahtzee() for _ in range(num_games)],
[yahtzee() for _ in range(n_tests)],
)
)

assert len(winning_games) == 460
assert len(winning_games) / n_tests == pytest.approx(0.046, abs=0.01)

0 comments on commit 7d8b830

Please sign in to comment.