use kalast::base::body::{Body, Properties};
use kalast::{ASTRONAUMICAL_UNIT, HOUR, V3};
use na::{Matrix3, Unit};
use std::path::Path;

#[test]
fn body_creation() {
    let name = "Dimorphos";
    let pos = V3::new(0., 1., 0.) * ASTRONAUMICAL_UNIT;
    let path = Path::new("tests/rsc/obj/dimorphos.obj");
    let prop = Properties::new(
        11.92 * HOUR, // rotation period
        11.92 * HOUR, // revolution period
        0.,           // obliquity
        500.,         // thermal inertia
        2146.,        // density
        600.,         // heat capacity
        0.07,         // albedo
        0.9,          // emissivity
    );
    let _body = Body::new(name, pos, path, prop);
}

#[test]
fn check_properties_computations() {
    let mut prop = Properties::new(
        11.92 * HOUR, // rotation period
        11.92 * HOUR, // revolution period
        0.,           // obliquity
        500.,         // thermal inertia
        2146.,        // density
        600.,         // heat capacity
        0.07,         // albedo
        0.9,          // emissivity
    );
    prop.set_time_step(30.);
    prop.set_number_thermal_skin_depth(1);

    assert_eq!(prop.conductivity(), 0.1941596769182976);
    assert_eq!(prop.diffusivity(), 0.00000015079192056407084);
    assert_eq!(prop.thermal_skin_depth(), 0.1425782732630658);
    assert_eq!(prop.ground_depth(), 0.1425782732630658);
    assert_eq!(prop.ground_step(), 0.004253825392242669);

    assert_eq!(prop.ground_vector().len(), 35);
    assert_eq!(prop.ground_vector()[0], 0.);
    assert_eq!(
        prop.ground_vector()[prop.ground_vector().len() - 1],
        0.1425782732630658
    );
    assert_eq!(
        *prop.rotation_axis(),
        Unit::new_normalize(V3::new(0., 0., 1.))
    );
    assert_eq!(prop.rotation_angle(), 0.004392607177838077);
    assert_eq!(
        *prop.rotation_matrix().matrix(),
        Matrix3::new(
            0.999990352516603,
            -0.00439259305196072,
            0.,
            0.00439259305196072,
            0.999990352516603,
            0.,
            0.,
            0.,
            1.
        )
    );
}
