Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create composite hypothesis tests #54

Open
drvinceknight opened this issue May 3, 2016 · 1 comment
Open

Create composite hypothesis tests #54

drvinceknight opened this issue May 3, 2016 · 1 comment
Labels

Comments

@drvinceknight
Copy link
Contributor

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())
@geraintpalmer
Copy link
Member

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 🐣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants