Skip to content

Commit

Permalink
use flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Bernhardsson committed Mar 20, 2018
1 parent ecafc0e commit a56a5a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -7,7 +7,7 @@ before_install:
- pip install pytest pytest-cov
- pip install coveralls
install:
- pip install pytest -r requirements.txt
- pip install pytest flaky -r requirements.txt
script:
- py.test --cov=convoys .
after_success:
Expand Down
8 changes: 8 additions & 0 deletions test_convoys.py
@@ -1,4 +1,5 @@
import datetime
import flaky
import matplotlib
import numpy
import pytest
Expand All @@ -22,6 +23,7 @@ def generate_censored_data(N, E, C):
return B, T


@flaky.flaky
def test_exponential_regression_model(c=0.3, lambd=0.1, n=100000):
X = numpy.ones((n, 1))
C = scipy.stats.bernoulli.rvs(c, size=(n,)) # did it convert
Expand Down Expand Up @@ -49,6 +51,7 @@ def test_exponential_regression_model(c=0.3, lambd=0.1, n=100000):
assert 0.70*(c_hi-c_lo) < (y_hi-y_lo) < 1.30*(c_hi-c_lo)


@flaky.flaky
def test_weibull_regression_model(cs=[0.3, 0.5, 0.7], lambd=0.1, k=0.5, n=100000):
X = numpy.array([[1] + [r % len(cs) == j for j in range(len(cs))] for r in range(n)])
C = numpy.array([bool(random.random() < cs[r % len(cs)]) for r in range(n)])
Expand Down Expand Up @@ -76,6 +79,7 @@ def test_weibull_regression_model(cs=[0.3, 0.5, 0.7], lambd=0.1, k=0.5, n=100000
assert 0.80*expected_time < model.predict_time(x) < 1.20*expected_time


@flaky.flaky
def test_weibull_regression_model_ci(c=0.3, lambd=0.1, k=0.5, n=100000):
X = numpy.ones((n, 1))
C = scipy.stats.bernoulli.rvs(c, size=(n,))
Expand All @@ -92,6 +96,7 @@ def test_weibull_regression_model_ci(c=0.3, lambd=0.1, k=0.5, n=100000):
assert 0.70*(c_hi-c_lo) < (y_hi-y_lo) < 1.30*(c_hi-c_lo)


@flaky.flaky
def test_gamma_regression_model(c=0.3, lambd=0.1, k=3.0, n=100000):
# TODO: this one seems very sensitive to large values for N (i.e. less censoring)
X = numpy.ones((n, 1))
Expand All @@ -108,6 +113,7 @@ def test_gamma_regression_model(c=0.3, lambd=0.1, k=3.0, n=100000):
assert 0.80*k/lambd < model.predict_time([1]) < 1.20*k/lambd


@flaky.flaky
def test_nonparametric_model(c=0.3, lambd=0.1, k=0.5, n=10000):
C = scipy.stats.bernoulli.rvs(c, size=(n,))
N = scipy.stats.uniform.rvs(scale=30./lambd, size=(n,))
Expand Down Expand Up @@ -150,9 +156,11 @@ def _test_plot_cohorts(cs=[0.3, 0.5, 0.7], k=0.5, lambd=0.1, n=10000, model='wei
assert 0.90*c < y < 1.10 * c


@flaky.flaky
def test_plot_cohorts_weibull():
_test_plot_cohorts(model='weibull')


@flaky.flaky
def test_plot_cohorts_nonparametric():
_test_plot_cohorts(model='nonparametric')

0 comments on commit a56a5a5

Please sign in to comment.