roll/tests/throw_test.py

35 lines
1.0 KiB
Python
Raw Permalink Normal View History

2023-08-13 20:46:47 +00:00
from hypothesis import given
from hypothesis import strategies as st
2023-08-13 18:53:51 +00:00
from roll.throw import Throw
2023-08-13 20:46:47 +00:00
@given(st.lists(st.integers(min_value=1), min_size=1), st.integers(min_value=2))
def test_throw(results: list[int], sides: int):
throw = Throw(results, sides=sides)
assert throw.total == sum(results)
2023-08-13 18:53:51 +00:00
assert not throw.is_critical_hit
assert not throw.is_critical_miss
2023-08-13 20:46:47 +00:00
@given(st.lists(st.integers(min_value=1), min_size=1), st.integers(min_value=2), st.integers())
def test_throw_with_modifier(results: list[int], sides: int, modifier: int):
throw = Throw(results, sides=sides, modifier=modifier)
assert throw.total == (sum(results) + modifier)
2023-08-13 18:53:51 +00:00
assert not throw.is_critical_hit
assert not throw.is_critical_miss
def test_critical_hit():
throw = Throw([20], sides=20)
assert throw.total == 20
assert throw.is_critical_hit
assert not throw.is_critical_miss
def test_critical_miss():
throw = Throw([1], sides=20)
assert throw.total == 1
assert not throw.is_critical_hit
assert throw.is_critical_miss