2018-09-29 14:21:04 +00:00
|
|
|
from hypothesis import given, assume
|
|
|
|
from hypothesis import strategies as st
|
2019-04-23 11:18:42 +00:00
|
|
|
|
2021-04-01 23:03:49 +00:00
|
|
|
from pyo3_pytests import othermod
|
2018-11-11 11:25:53 +00:00
|
|
|
|
2022-02-14 07:42:06 +00:00
|
|
|
INTEGER32_ST = st.integers(min_value=(-(2**31)), max_value=(2**31 - 1))
|
2018-11-11 11:25:53 +00:00
|
|
|
USIZE_ST = st.integers(min_value=othermod.USIZE_MIN, max_value=othermod.USIZE_MAX)
|
2018-09-29 14:21:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
@given(x=INTEGER32_ST)
|
|
|
|
def test_double(x):
|
2018-11-11 11:25:53 +00:00
|
|
|
expected = x * 2
|
2022-02-14 07:42:06 +00:00
|
|
|
assume(-(2**31) <= expected <= (2**31 - 1))
|
2018-09-29 14:21:04 +00:00
|
|
|
assert othermod.double(x) == expected
|
|
|
|
|
2018-11-11 11:25:53 +00:00
|
|
|
|
2018-09-29 14:21:04 +00:00
|
|
|
def test_modclass():
|
|
|
|
# Test that the repr of the class itself doesn't crash anything
|
|
|
|
repr(othermod.ModClass)
|
|
|
|
|
|
|
|
assert isinstance(othermod.ModClass, type)
|
|
|
|
|
2018-11-11 11:25:53 +00:00
|
|
|
|
2018-09-29 14:21:04 +00:00
|
|
|
def test_modclass_instance():
|
|
|
|
mi = othermod.ModClass()
|
|
|
|
|
|
|
|
repr(mi)
|
|
|
|
repr(mi.__class__)
|
|
|
|
|
|
|
|
assert isinstance(mi, othermod.ModClass)
|
|
|
|
assert isinstance(mi, object)
|
|
|
|
|
2018-11-11 11:25:53 +00:00
|
|
|
|
2018-09-29 14:21:04 +00:00
|
|
|
@given(x=USIZE_ST)
|
|
|
|
def test_modclas_noop(x):
|
|
|
|
mi = othermod.ModClass()
|
|
|
|
|
|
|
|
assert mi.noop(x) == x
|