Int pair generation is giving me negative values, but I dont think it should?

12 views
Skip to first unread message

Nick

unread,
Sep 19, 2023, 5:37:10 PM9/19/23
to Hypothesis users
I have code like this, for registering the default strat for 2D positions (as int pairs):
SIZE = 5
posTyp = tuple[int, int]
def posST(size=SIZE):
  return st.tuples(st.integers(min_value=0, max_value=size-1),
                   st.integers(min_value=0, max_value=size-1))
st.register_type_strategy(
  tuple,
  lambda typ:
    posST() if typ == posTyp else \
      st.tuples(*[st.from_type(t) for t in get_args(typ)])
)


Then a test function (inside a TestCase subclass) like:
@given(thingPos=...)
def testThing(self, thingPos: posTyp):
  ....

Apparently in one of the examples I'm getting a pos of (0, -1), which naturally breaks my code.
But I don't think i should be getting that? I'm not sure what is the right way to register that int pairs should have a default strategy of ([0-4], [0-4]). Am I doing something wrong here?

I also have some other not-really-related questions, wondering if I should create a separate thread for each question or just ask them all in one thread.

Thanks!
Reply all
Reply to author
Forward
0 new messages