from backtesting import statistics


def test_moving_block_bootstrap_is_deterministic_and_handles_constant_series():
    first = statistics.moving_block_bootstrap_ci(
        [12.5] * 120,
        block_size=15,
        n_resamples=200,
        seed=7,
    )
    second = statistics.moving_block_bootstrap_ci(
        [12.5] * 120,
        block_size=15,
        n_resamples=200,
        seed=7,
    )

    assert first == second
    assert first == {"estimate": 12.5, "ci_low": 12.5, "ci_high": 12.5, "n": 120}


def test_summarize_returns_reports_observations_and_block_bootstrap_interval():
    summary = statistics.summarize_returns(
        [10.0, -5.0, 20.0, -10.0],
        block_size=2,
        n_resamples=200,
        seed=3,
    )

    assert summary["n"] == 4
    assert summary["mean"] == 3.75
    assert summary["median"] == 2.5
    assert summary["win_rate"] == 50.0
    assert summary["mean_ci_low"] <= summary["mean"] <= summary["mean_ci_high"]
