The Story:
Currently, I have a function-under-test that expects a list of lists of integers with the following rules:
- number of sublists (let's call i
N
) can be from 1 to 50 - number of values inside sublists is the same for all sublists (rectangular form) and should be >= 0 and <= 5
- values inside sublists cannot be more than or equal to the total number of sublists. In other words, each value inside a sublist is an integer >= 0 and <
N
Sample valid inputs:
[[0]]
[[2, 1], [2, 0], [3, 1], [1, 0]]
[[1], [0]]
Sample invalid inputs:
[[2]] # 2 is more than N=1 (total number of sublists)
[[0, 1], [2, 0]] # 2 is equal to N=2 (total number of sublists)
I'm trying to approach it with property-based-testing and generate different valid inputs with hypothesis
library and trying to wrap my head around lists()
and integers()
, but cannot make it work:
- the condition #1 is easy to approach with
lists()
andmin_size
andmax_size
arguments - the condition #2 is covered under
Chaining strategies together
- the condition #3 is what I'm struggling with - cause, if we use the
rectangle_lists
from the above example, we don't have a reference to the length of the "parent" list
The Question:
How can I limit the integer values inside sublist to be less than the total number of sublists?
Will edit and provide my current attempts shortly
Aucun commentaire:
Enregistrer un commentaire