import pytest


@pytest.fixture
def mut():
    """Returns the module under test."""
    from better import lib
    return lib


def test_results_percentile(mut):
    """Ensure the Results.percentile function returns the right value."""
    Results = mut.Results
    r = Results([
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10
    ])

    assert r.percentile(50.0) == 5


def test_forecast_average(mut):
    throughputs = [2, 2, 2, 2]
    backlog_size = 2 * 5

    result = mut.Forecaster().forecast_avg(throughputs, backlog_size)  # Fix the seed so we get predictable results
    assert result == 5


def test_forecast_sanity(mut):
    """With a uniform historical distribution, we should get the same result for all percentiles."""
    throughputs = [2, 2, 2, 2]
    backlog_size = 2 * 5

    result = mut.Forecaster().forecast(throughputs, backlog_size, seed=1)

    assert result.percentile(50.0) == 5

@@ -942,28 +942,503 @@
 esult.percentile(50.0) == 5%0A
+%0A%0Adef test_forecast_with_backtest(mut):%0A    %22%22%22With a known set of throughputs and a known backlog, we should get the result we expect.%22%22%22%0A    throughputs = %5B%0A        14, 13, 1, 2, 12, 13, 7, 14%0A    %5D%0A    backlog_size = sum(throughputs)%0A%0A    result = mut.Forecaster().forecast(throughputs, backlog_size, seed=1)%0A    assert result.percentile(50.0) == 8%0A    assert result.percentile(75.0) == 10%0A    assert result.percentile(85.0) == 10%0A    assert result.percentile(95.0) == 12%0A

Add a backtest