File size: 1,946 Bytes
b39dfd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Unit tests for high-accuracy sampling verification."""

import json
import importlib.util
from pathlib import Path
import pytest
import sys

sys.path.insert(0, str(Path(__file__).parent.parent / "src"))

from sampler import (
    verify_polylog_step_scaling,
    verify_intrinsic_dimension_scaling,
    verify_log_concave_gradient_sampler,
)


def test_polylog_step_scaling():
    res = verify_polylog_step_scaling([1e-2, 1e-4, 1e-6])
    assert res["verified"] is True
    assert res["polylog_exponent_estimate"] < 3.0
    assert len(res["step_data"]) == 3


def test_intrinsic_dimension_scaling():
    res = verify_intrinsic_dimension_scaling(d_star=5, full_d=500, delta=1e-3)
    assert res["verified"] is True
    assert pytest.approx(res["theoretical_speedup"]) == 100.0


def test_log_concave_gradient_sampler():
    res = verify_log_concave_gradient_sampler(dimension=3, target_accuracy=1e-2)
    assert res["verified"] is True
    assert res["empirical_mean_error"] < 0.3
    assert res["empirical_cov_error"] < 0.4


def test_evidence_bundle():
    bundle_path = Path(__file__).parent.parent / "evidence" / "bundle.json"
    if bundle_path.exists():
        data = json.loads(bundle_path.read_text())
        assert data["paper_id"] == "71132"
        assert len(data["claims"]) == 3


def test_evidence_generation_is_stable(tmp_path, monkeypatch):
    generator_path = Path(__file__).parent.parent / "generate_evidence.py"
    spec = importlib.util.spec_from_file_location("high_accuracy_generate_evidence", generator_path)
    module = importlib.util.module_from_spec(spec)
    assert spec.loader is not None
    spec.loader.exec_module(module)

    monkeypatch.setattr(sys, "argv", ["generate_evidence.py", "--output-dir", str(tmp_path)])
    module.main()
    first = json.loads((tmp_path / "bundle.json").read_text())

    module.main()
    second = json.loads((tmp_path / "bundle.json").read_text())

    assert second == first