use gonidium::{Backend, PythonBackend, Value, interp_eval, lower, optimize, parse_dsl};

#[test]
fn e2e_lower_opt_codegen_matches_interp() {
    let src = r#"
    |x: f64|
    y = x + 0
    softplus(y)
    "#;
    let func = parse_dsl(src).expect("parse");
    let dag = lower(&func).expect("lower").dag;
    let base = interp_eval(&dag, &[Value::F64(1.25)]).expect("interp");

    let opt_dag = optimize(&dag).expect("optimize");
    let after = interp_eval(&opt_dag, &[Value::F64(1.25)]).expect("interp");
    assert_eq!(base, after);

    let backend = PythonBackend;
    let py = backend.emit_kernel(&opt_dag, "kernel");
    assert!(py.contains("import math"));
    assert!(py.contains("def kernel("));
}

#[test]
fn e2e_floor_ceil_codegen_matches_interp() {
    let src = r#"
    |x: f64|
    y = floor(x)
    z = ceil(x)
    y + z
    "#;
    let func = parse_dsl(src).expect("parse");
    let dag = lower(&func).expect("lower").dag;
    let base = interp_eval(&dag, &[Value::F64(1.25)]).expect("interp");

    let opt_dag = optimize(&dag).expect("optimize");
    let after = interp_eval(&opt_dag, &[Value::F64(1.25)]).expect("interp");
    assert_eq!(base, after);

    let backend = PythonBackend;
    let py = backend.emit_kernel(&opt_dag, "kernel");
    assert!(py.contains("import math"));
    assert!(py.contains("def kernel("));
    assert!(py.contains("float(math.floor"));
    assert!(py.contains("float(math.ceil"));
}
