-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcreation_test.py
More file actions
74 lines (49 loc) · 1.75 KB
/
creation_test.py
File metadata and controls
74 lines (49 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import icepool
import pytest
from icepool import Die, Deck, d6
def test_d_syntax():
assert icepool.d6.quantities() == (1, ) * 6
assert icepool.d6.probability(0) == 0.0
assert icepool.d6.probability(1) == pytest.approx(1.0 / 6.0)
assert icepool.d6.probability(6) == pytest.approx(1.0 / 6.0)
assert icepool.d6.probability(7) == 0.0
def test_z():
assert icepool.d(6) - 1 == icepool.z(6)
def test_coin():
b = icepool.coin(1, 2)
c = icepool.coin(1, 2)
assert b.probabilities() == pytest.approx([0.5, 0.5])
assert c.probabilities() == pytest.approx([0.5, 0.5])
def test_list_no_min_outcome():
result = icepool.Die([2, 3, 3, 4, 4, 4, 5, 5, 6])
expected = 2 @ icepool.d3
assert result.equals(expected)
def test_d6s():
d6 = icepool.d6
assert d6.equals(icepool.d(6))
assert d6.equals(icepool.Die([d6]))
assert d6.equals(icepool.Die([icepool.d3, icepool.d3 + 3]))
assert d6.equals(icepool.Die({1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1}))
assert d6.equals(icepool.Die([1, 2, 3, 4, 5, 6]))
def test_return_self():
pytest.skip()
die = icepool.d6
assert icepool.Die(die) is die
assert icepool.Die([die]) is die
def test_negative_weight_error():
with pytest.raises(ValueError):
icepool.Die({1: -1})
with pytest.raises(ValueError):
icepool.Die([1], times=[-1])
def test_not_orderable_error():
with pytest.raises(TypeError):
icepool.Die([None])
def test_implicit_mapping_error():
with pytest.raises(TypeError):
icepool.d6 + {}
def test_empty_tuple():
result = icepool.Die([()])
assert result.equals(result + ())
def test_denominator():
result = icepool.Die([icepool.d(3), icepool.d(4), icepool.d(6)])
assert result.denominator() == 36