Skip to content

Commit d0c764c

Browse files
Create test_experiment.py
1 parent cdd39ef commit d0c764c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_experiment.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import random
2+
from probability_calculator import Hat, experiment
3+
4+
5+
def test_experiment_probability_range():
6+
hat = Hat(red=3, blue=2)
7+
prob = experiment(hat, {"red": 1}, num_balls_drawn=2, num_experiments=200)
8+
assert 0 <= prob <= 1
9+
10+
11+
def test_experiment_reproducibility():
12+
random.seed(123)
13+
14+
hat = Hat(red=5, blue=1)
15+
prob1 = experiment(hat, {"red": 2}, 3, 100)
16+
17+
random.seed(123)
18+
hat = Hat(red=5, blue=1)
19+
prob2 = experiment(hat, {"red": 2}, 3, 100)
20+
21+
assert prob1 == prob2 # deterministic
22+
23+
24+
def test_experiment_success_condition():
25+
hat = Hat(red=5, blue=5)
26+
27+
prob = experiment(
28+
hat,
29+
expected_balls={"red": 1},
30+
num_balls_drawn=1,
31+
num_experiments=500,
32+
)
33+
34+
# Probability of drawing at least 1 red ball from 10 balls with 5 red = 0.5
35+
assert 0.3 < prob < 0.7

0 commit comments

Comments
 (0)