# /// script
# requires-python = ">=3.11"
# dependencies = []
# ///
"""Print language-neutral Gauss collocation fixtures."""

import json
from pathlib import Path
import sys

sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "reference"))
from check_port import advance
from gauss_legendre_4 import step


def build():
    inputs = [
        ("canonical", 0, (0.7,0.3), 0.34, 3),
        ("rotation", 0, (0.7,0.4,0.8), 0.23, 4),
        ("forced", 0.4, (0.3,-0.2), 0.32, 2),
        ("imaginary", 2, (1,0), -0.5, 1),
    ]
    return {
        "format": 1, "method": "gauss-legendre-4", "version": "0.1.0",
        "interface": "step(f,J,t,y,h) returns y(t+h) for a signed h; repeat for the specified number of steps.",
        "problems": {
            "canonical": "P=p+q^2/2; f=[P,-q-q*P]; J=[[q,1],[-1-P-q^2,-q]].",
            "rotation": "f=[-y*z/6,2*x*z/3,-x*y/2]; J=[[0,-z/6,-y/6],[2*z/3,0,2*x/3],[-y/2,-x/2,0]].",
            "forced": "f=[t-x*y,t^2-y+x]; J=[[-y,-x],[1,-1]].",
            "imaginary": "f=[-40*y,40*x]; J=[[0,-40],[40,0]].",
        },
        "cases": [
            {"problem": problem, "t": t, "y": y, "h": h, "steps": n,
             "expected": advance(step, problem, t, y, h, n), "tol": 3e-12}
            for problem,t,y,h,n in inputs
        ],
    }


if __name__ == "__main__":
    print(json.dumps(build(), indent=2))
