"""Auto-Repair-Loop-Primitive: Stopp bei 100 %, Stillstand, Limit."""
import auto_loop


async def test_fertig_ohne_repair():
    async def rep():
        raise AssertionError("darf bei 100 % nie reparieren")

    r = await auto_loop.auto_repair_loop("x", 10.0, rep)
    assert r == {"ebene": "x", "note": 10.0, "runden": 0, "grund": "fertig"}


async def test_verbessert_bis_voll():
    noten = iter([9.0, 10.0])

    async def rep():
        return next(noten)

    r = await auto_loop.auto_repair_loop("inv", 8.0, rep)  # 8.0 → 9.0 → 10.0
    assert r["grund"] == "fertig" and r["runden"] == 2


async def test_stillstand():
    async def rep():
        return 8.0  # Repair bewegt nichts

    r = await auto_loop.auto_repair_loop("art", 8.0, rep)
    assert r["grund"] == "stillstand" and r["runden"] == 1
    assert r["note"] == 8.0


async def test_limit():
    stand = {"n": 1.0}

    async def rep():
        stand["n"] += 0.1  # verbessert stetig, erreicht aber nie 10.0
        return stand["n"]

    r = await auto_loop.auto_repair_loop("guide", 1.0, rep, max_iter=10)
    assert r["grund"] == "limit" and r["runden"] == 10
