roll/tests/throw_test.py

35 lines
1.0 KiB
Python

from hypothesis import given
from hypothesis import strategies as st
from roll.throw import Throw
@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)
assert not throw.is_critical_hit
assert not throw.is_critical_miss
@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)
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