Skip to content

Instantly share code, notes, and snippets.

@rhizoome
Created February 26, 2016 14:01
Show Gist options
  • Save rhizoome/fa2d4425f4505a6f8399 to your computer and use it in GitHub Desktop.
Save rhizoome/fa2d4425f4505a6f8399 to your computer and use it in GitHub Desktop.
@st.composite
def provide_require_st(draw):
commands = draw(range_intagers_st)
provides = draw(
st.lists(
st.lists(range_intagers_st),
min_size = commands,
max_size = commands
)
)
provides_set = set()
for command in provides:
provides_set.update(command)
requires = []
if provides_set:
for command in provides:
if command:
max_prov = max(command)
else:
max_prov = 0
sample = st.sampled_from(provides_set).filter(
lambda n: max_prov < n
)
requires.append(draw(st.lists(sample)))
return (provides, requires)
I did some hairy thing and it doesn't work. Could anybody point out how to do it right?
We have commands that can provide resources and require resources. So I wanted to generate a list of commands with the
resources they provide (integers) (lines 3-10) and then I add them to a set in order to know what can be required
(ines 11-13). If I return on line 14, provides and provides_set are defined as expected.
Now I want to draw from the provides_set for every command to find what they require. Laking a good strategy I defined
that max(provides) < min(requires) to avoid cycles. When I add lines 15-24 I get empty lists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment