Skip to content

Commit

Permalink
Minor test tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
Ezibenroc committed Aug 20, 2024
1 parent 18ebc0c commit d39de71
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
39 changes: 32 additions & 7 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,50 @@
range_big_step = uint18.flatmap(lambda n:
st.builds(range, st.just(n),
st.integers(
min_value=n + 1, max_value=n + range_max_size),
st.integers(min_value=2**8, max_value=range_max_size // 8)))
min_value=n+1, max_value=n+range_max_size),
st.integers(min_value=2**8, max_value=range_max_size//8)))

range_small_step = uint18.flatmap(lambda n:
st.builds(range, st.just(n),
st.integers(
min_value=n + 1, max_value=n + range_max_size),
min_value=n+1, max_value=n+range_max_size),
st.integers(min_value=1, max_value=2**8)))

range_power2_step = uint18.flatmap(lambda n:
st.builds(range, st.just(n),
st.integers(
min_value=n + 1, max_value=n + range_max_size),
min_value=n+1, max_value=n+range_max_size),
st.integers(min_value=0, max_value=8).flatmap(
lambda n: st.just(2**n),
lambda n: st.just(2**n)
)))

hyp_range = range_big_step | range_small_step | range_power2_step | st.sampled_from(
[range(0, 0)]) # last one is an empty range
range_huge_interval = uint18.flatmap(lambda n:
st.builds(range, st.just(n),
st.integers(
min_value=n+2**52, max_value=n+2**63),
st.integers(min_value=2**45, max_value=2**63)))

# Build a list of values of the form a * 2**16 + b with b in [-2,+2]
# In other words, numbers that are close (or equal) to a multiple of 2**16
multiple_2p16 = st.sets(
st.builds(
int.__add__, st.builds(
int.__mul__,
st.integers(min_value=1, max_value=2**32),
st.just(2**16)
),
st.integers(min_value=-2, max_value=+2)
),
max_size=100)

hyp_range = (
range_big_step |
range_small_step |
range_power2_step |
range_huge_interval |
multiple_2p16 |
st.sampled_from([range(0, 0)]) # last one is an empty range
)
# would be great to build a true random set, but it takes too long and hypothesis does a timeout...
hyp_set: st.SearchStrategy[set[int]] = st.builds(set, hyp_range)
hyp_array = st.builds(lambda x: array.array('I', x), hyp_range)
Expand Down
6 changes: 3 additions & 3 deletions test_state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from hypothesis import settings
from dataclasses import dataclass
from pyroaring import BitMap, BitMap64
from test64 import hyp_range, uint64
from test64 import hyp_collection, uint64

BitMapClass = BitMap64

Expand All @@ -25,7 +25,7 @@ def __post_init__(self):
class SetComparison(RuleBasedStateMachine):
collections = Bundle("collections")

@rule(target=collections, val=hyp_range)
@rule(target=collections, val=hyp_collection)
def init_collection(self, val):
return Collection(test=BitMapClass(val), ref=set(val))

Expand Down Expand Up @@ -110,7 +110,7 @@ def flip_inplace(self, col, start, size):


TestTrees = SetComparison.TestCase
TestTrees.settings = settings(max_examples=100, stateful_step_count=200)
TestTrees.settings = settings(max_examples=100, stateful_step_count=100)

if __name__ == "__main__":
unittest.main()

0 comments on commit d39de71

Please sign in to comment.