Skip to content

Commit

Permalink
Add hypothesis testing
Browse files Browse the repository at this point in the history
  • Loading branch information
c-bata committed Mar 9, 2021
1 parent 91bf34a commit b112c0c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __pycache__/
.eggs/
*.egg-info/
.tox/
.hypothesis

tmp/
benchmark/*.json
Expand Down
26 changes: 26 additions & 0 deletions tests/test_fuzzing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import hypothesis.extra.numpy as npst
import unittest
from hypothesis import given, strategies as st

from cmaes import CMA


class TestFuzzing(unittest.TestCase):
@given(
data=st.data(),
)
def test_cma_tell(self, data):
dim = data.draw(st.integers(min_value=2, max_value=100))
mean = data.draw(npst.arrays(dtype=float, shape=dim))
sigma = data.draw(st.floats(min_value=1e-16))
n_iterations = data.draw(st.integers(min_value=1))
optimizer = CMA(mean, sigma)
popsize = optimizer.population_size
for _ in range(n_iterations):
tell_solutions = data.draw(
st.lists(st.tuples(npst.arrays(dtype=float, shape=dim), st.floats()),
min_size=popsize, max_size=popsize)
)
optimizer.ask()
optimizer.tell(tell_solutions)
optimizer.ask()

0 comments on commit b112c0c

Please sign in to comment.