//! Rust NUVMAP — Cross-Validation Integration Test
//!
//! Runs the same test data as Python/R/Julia and validates output matches.

use silversight::q16::*;
use silversight::nuvmap::{self, Engine};

fn test_data() -> Vec<std::collections::HashMap<String, i32>> {
    vec![
        nuvmap::make_input(1, of_float(0.8), of_float(0.75), of_float(0.05), "achiral_stable"),
        nuvmap::make_input(2, of_float(0.3), of_float(0.4), of_float(0.2), "left_handed_mass_bias"),
        nuvmap::make_input(3, of_float(0.1), of_float(0.15), of_float(0.6), "chiral_scarred"),
        nuvmap::make_input(4, of_float(0.5), of_float(0.5), of_float(0.1), "right_handed_vector_bias"),
        nuvmap::make_input(5, of_float(0.9), of_float(0.85), of_float(0.02), "achiral_stable"),
    ]
}

fn expected_q_i() -> [i32; 5] { [73, 0, 0, 2, 10780] }
fn expected_e_i() -> [f64; 5] { [7.7487640380859375, 0.4666595458984375, 0.0333404541015625, 0.93328857421875, 99.90243530273438] }

#[test]
fn test_nuvmap_projector() {
    let data = test_data();
    let engine = Engine::default();
    let surface = engine.project(&data);

    assert_eq!(surface.cells.len(), 5);
    assert_eq!(surface.total_qubits, 10855);
    assert!((to_float(surface.bekenstein_bound) - 21.81689453125).abs() < 1e-4);

    let exp_q = expected_q_i();
    let exp_e = expected_e_i();
    for (i, cell) in surface.cells.iter().enumerate() {
        assert_eq!(cell.q_i, exp_q[i], "cell {i} q_i mismatch");
        let e_f = to_float(cell.e_i);
        assert!((e_f - exp_e[i]).abs() < 1e-4, "cell {i} e_i mismatch: got {e_f}, expected {}", exp_e[i]);
    }
}
