import json from robotics.eval.stats import compare, main, wilson def test_wilson_known_value(): lo, hi = wilson(45, 50) assert abs(lo - 0.786) < 0.005 and abs(hi - 0.957) < 0.005 def test_wilson_edges(): assert wilson(0, 0) == (0.0, 1.0) lo, hi = wilson(50, 50) assert hi == 1.0 and lo > 0.9 def test_compare_significance(): assert compare(30, 100, 50, 100)["p_value"] < 0.01 assert compare(50, 100, 52, 100)["p_value"] > 0.5 def test_cli(tmp_path, capsys): f = tmp_path / "r.jsonl" f.write_text("\n".join(json.dumps({"run": r, "suite": "s", "success": i < k}) for r, k in [("A", 3), ("B", 8)] for i in range(10))) main([str(f), "--compare", "A", "B"]) out = capsys.readouterr().out assert "30.0%" in out and "80.0%" in out and "B - A: +50.0%" in out