Ciw icon indicating copy to clipboard operation
Ciw copied to clipboard

Create composite hypothesis tests

Open drvinceknight opened this issue 9 years ago • 1 comments

Instead of a bunch of boilerplate for a hypothesis test you could simple have:

@given(sim=simulations(max_nodes=2))
def test_...

Working on this on Axelrod at the moment it's actually pretty straightforward, here's how to build a decorator that creates a matches strategy:

from hypothesis.strategies import composite, integers, tuples, sampled_from, floats

import axelrod as axl


@composite
def matches(draw, players=axl.strategies, min_turns=1, max_turns=200, noise=False):
    strategies = draw(tuples(sampled_from(players), sampled_from(players)))
    players = [s() for s in strategies]
    turns = draw(integers(min_value=min_turns, max_value=max_turns))
    if noise:
        noise = draw(floats(min_value=0.05, max_value=1))
    else:
        noise = 0
    match = axl.Match(players, turns=turns, noise=noise)
    return match

print(matches().example())
print(matches().example().play())

drvinceknight avatar May 03 '16 07:05 drvinceknight

Sounds interesting. Will need a bit of planning as a simulation object is very complicated, lots of optional stuff, things relying on other things etc. but looks good :D 🐣

geraintpalmer avatar May 04 '16 09:05 geraintpalmer