From 8b5a7cebf57ee0173992ed1d73004d8a17038c8f Mon Sep 17 00:00:00 2001 From: Richard Darst Date: Wed, 23 Aug 2023 17:38:43 +0300 Subject: [PATCH] yahtzee_sol: Test against a distribution - Make Python match the other examples and instructions - Closes: #158 --- content/code/python/yahtzee_sol.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/content/code/python/yahtzee_sol.py b/content/code/python/yahtzee_sol.py index 9744694..81f1570 100644 --- a/content/code/python/yahtzee_sol.py +++ b/content/code/python/yahtzee_sol.py @@ -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)