#!/usr/bin/env python3
from __future__ import annotations

import numpy as np

import analyze_phase5 as a


def main() -> None:
    adjusted = a.holm({"A1": 0.001, "A2": 0.02, "A3": 0.04, "A4": 0.5})
    assert adjusted == {"A1": 0.004, "A2": 0.06, "A3": 0.08, "A4": 0.5}
    assert a.ci(np.arange(100, dtype=np.float64)) == [2.475, 96.52499999999999]
    runs = [
        {"blocks": np.asarray([[10.0, 2.0]] * 48)},
        {"blocks": np.asarray([[20.0, 4.0]] * 48)},
        {"blocks": np.asarray([[30.0, 6.0]] * 48)},
    ]
    draws = a.hierarchical_draws(runs, np.random.default_rng(a.SEED))
    assert draws.shape == (a.RESAMPLES,)
    assert np.allclose(draws, 5.0)
    assert a.point_efficiency(runs) == 5.0
    idle_blocks = np.asarray([[0.0, 0.0]] + [[10.0, 2.0]] * 47)
    idle_draws = a.hierarchical_draws(
        [{"blocks": idle_blocks}], np.random.default_rng(a.SEED)
    )
    assert np.all(np.isfinite(idle_draws))
    assert np.allclose(idle_draws, 5.0)
    assert a.point_efficiency([{"blocks": idle_blocks}]) == 5.0
    assert a.two_sided_p(np.asarray([-1.0, 1.0])) == 1.0
    print("phase5 analysis: PASS")


if __name__ == "__main__":
    main()
