extends SceneTree const Cycle = preload("res://scripts/mana/mana_reserve_cycle.gd") var checks := 0 var failures := 0 func expect(ok: bool, message: String) -> void: checks += 1 if not ok: failures += 1 push_error(message) func run(before: int, demand: int, minutes: int) -> int: var cycle = Cycle.new() cycle.start_at(360) var amount := before for minute: int in range(361, 360 + minutes + 1): var result: Dictionary = cycle.advance_to(minute, amount, demand) amount = int(result[&"after"]) return amount func _initialize() -> void: expect(Cycle.INITIAL_MANA == 100 and Cycle.CAPACITY == 300 and Cycle.WORLD_TREE_GENERATION == 20, "approved A06 values") # Proposal comparison table (recommended column), F=0, start 360. expect(run(100, 2, 120) == 300, "low load fills to capacity") expect(run(100, 16, 120) == 148, "normal load 100+12*(20-16)") expect(run(100, 63, 120) == 0, "overload depletes") expect(run(0, 16, 10) == 4, "zero reserve recovers on next boundary") expect(run(300, 2, 10) == 300, "full reserve keeps capacity") var cycle = Cycle.new() expect(not cycle.advance_to(370, 100, 16)[&"ok"], "unstarted cycle rejected") expect(cycle.start_at(365) and cycle.get_minute() == 360, "start floors to boundary") expect(not cycle.advance_to(369, 100, 16)[&"processed"], "non-boundary minute is a no-op") var flow: Dictionary = cycle.advance_to(370, 100, 63)[&"flow"] expect(flow[&"after"] == 57 and flow[&"consumed"] == 63 and flow[&"overflow"] == 0, "demand paid from generation and reserve") var saved: Dictionary = cycle.create_snapshot() expect(not cycle.advance_to(370, 57, 63)[&"processed"] and cycle.create_snapshot() == saved, "same boundary never consumed twice") expect(not cycle.advance_to(360, 57, 63)[&"ok"], "time reversal rejected") expect(not cycle.advance_to(380, -1, 0)[&"ok"] and cycle.create_snapshot() == saved, "negative reserve rejected without change") var high = Cycle.new() high.start_at(360) flow = high.advance_to(370, 525, 16)[&"flow"] expect(flow[&"after"] == 300 and flow[&"overflow"] == 229, "amount raised above capacity between boundaries settles with recorded overflow") var high_restored = Cycle.new() expect(high_restored.restore_snapshot(high.create_snapshot()), "over-capacity before survives snapshot validation") var skipped: Dictionary = cycle.advance_to(400, 57, 63) expect(skipped[&"boundaries"] == 3 and skipped[&"after"] == 0 and skipped[&"flow"][&"shortage"] == 43, "skipped boundaries settle in order") var restored = Cycle.new() expect(restored.restore_snapshot(cycle.create_snapshot()) and restored.create_snapshot() == cycle.create_snapshot(), "snapshot round trip") var corrupt: Dictionary = cycle.create_snapshot() corrupt[&"last_flow"][&"after"] += 1 var untouched = Cycle.new() expect(not untouched.restore_snapshot(corrupt) and untouched.get_minute() == -1, "tampered flow rejected atomically") corrupt = cycle.create_snapshot() corrupt[&"capacity"] = 600 expect(not untouched.restore_snapshot(corrupt), "foreign policy capacity rejected") corrupt = cycle.create_snapshot() corrupt[&"minute"] = 405 expect(not untouched.restore_snapshot(corrupt), "off-boundary minute rejected") # Furnace is judged after natural generation and demand payment. expect(not Cycle.furnace_offer_accepted(200, 16), "B=200 base_after 204 free 96 rejected") expect(Cycle.furnace_offer_accepted(196, 16), "B=196 base_after 200 free 100 accepted") expect(not Cycle.furnace_offer_accepted(300, 16), "B=300 full rejected") expect(Cycle.plan(196, 16, 100, 360, 370)[&"after"] == 300, "accepted furnace offer fills exactly") expect(Cycle.amount_is_valid(0) and Cycle.amount_is_valid(300) and not Cycle.amount_is_valid(301) and not Cycle.amount_is_valid(-1) and not Cycle.amount_is_valid(1.5), "legacy amount bounds") print("%s: %d checks" % ["PASS" if failures == 0 else "FAIL", checks]) quit(failures)