#![allow(non_snake_case)]

extern crate rand;
extern crate MBrane;

use rand::Rng;
use MBrane::Vector::Vector3D::*;

#[test]
fn vector3d_initialization() {
    let mut rng = rand::thread_rng();

    let rx = rng.gen::<f64>();
    let ry = rng.gen::<f64>();
    let rz = rng.gen::<f64>();

    let vector = Vector3D {
        X: rx,
        Y: ry,
        Z: rz,
    };

    assert_eq!(rx, vector.X);
    assert_eq!(ry, vector.Y);
    assert_eq!(rz, vector.Z);
}

#[test]
fn vector3d_new_initialization() {
    let mut rng = rand::thread_rng();

    let rx = rng.gen::<f64>();
    let ry = rng.gen::<f64>();
    let rz = rng.gen::<f64>();

    let vector = Vector3D {
        X: rx,
        Y: ry,
        Z: rz,
    };

    let new_vector = vector.New(rx, ry, rz);

    assert_eq!(rx, new_vector.X);
    assert_eq!(ry, new_vector.Y);
    assert_eq!(rz, new_vector.Z);
}

#[test]
fn vector3d_magnitude() {
    let mut rng = rand::thread_rng();

    let rx = rng.gen::<f64>();
    let ry = rng.gen::<f64>();
    let rz = rng.gen::<f64>();

    let rresult = ((rx * rx) + (ry * ry) + (rz * rz)).sqrt();

    let vector = Vector3D {
        X: rx,
        Y: ry,
        Z: rz,
    };

    assert_eq!(rresult, vector.Magnitude());
}

#[test]
fn vector3d_normalization() {
    let mut rng = rand::thread_rng();

    let rx = rng.gen::<f64>();
    let ry = rng.gen::<f64>();
    let rz = rng.gen::<f64>();

    let rxres = rx / ((rx * rx) + (ry * ry) + (rz * rz)).sqrt();
    let ryres = ry / ((rx * rx) + (ry * ry) + (rz * rz)).sqrt();
    let rzres = rz / ((rx * rx) + (ry * ry) + (rz * rz)).sqrt();

    let mut vector = Vector3D {
        X: rx,
        Y: ry,
        Z: rz,
    };

    vector.Normalize();

    assert_eq!(rxres, vector.X);
    assert_eq!(ryres, vector.Y);
    assert_eq!(rzres, vector.Z);
}

#[test]
fn vector3d_addition() {
    let mut rng = rand::thread_rng();

    let rx_lhs = rng.gen::<f64>();
    let ry_lhs = rng.gen::<f64>();
    let rz_lhs = rng.gen::<f64>();

    let rx_rhs = rng.gen::<f64>();
    let ry_rhs = rng.gen::<f64>();
    let rz_rhs = rng.gen::<f64>();

    let rx_result = rx_lhs + rx_rhs;
    let ry_result = ry_lhs + ry_rhs;
    let rz_result = rz_lhs + rz_rhs;

    let lhs = Vector3D {
        X: rx_lhs,
        Y: ry_lhs,
        Z: rz_lhs,
    };
    let rhs = Vector3D {
        X: rx_rhs,
        Y: ry_rhs,
        Z: rz_rhs,
    };

    let result = lhs + rhs;

    assert_eq!(rx_result, result.X);
    assert_eq!(ry_result, result.Y);
    assert_eq!(rz_result, result.Z);
}

#[test]
fn vector3d_substraction() {
    let mut rng = rand::thread_rng();

    let rx_lhs = rng.gen::<f64>();
    let ry_lhs = rng.gen::<f64>();
    let rz_lhs = rng.gen::<f64>();

    let rx_rhs = rng.gen::<f64>();
    let ry_rhs = rng.gen::<f64>();
    let rz_rhs = rng.gen::<f64>();

    let rx_result = rx_lhs - rx_rhs;
    let ry_result = ry_lhs - ry_rhs;
    let rz_result = rz_lhs - rz_rhs;

    let lhs = Vector3D {
        X: rx_lhs,
        Y: ry_lhs,
        Z: rz_lhs,
    };
    let rhs = Vector3D {
        X: rx_rhs,
        Y: ry_rhs,
        Z: rz_rhs,
    };

    let result = lhs - rhs;

    assert_eq!(rx_result, result.X);
    assert_eq!(ry_result, result.Y);
    assert_eq!(rz_result, result.Z);
}

#[test]
fn vector3d_multiplication() {
    let mut rng = rand::thread_rng();

    let rx_lhs = rng.gen::<f64>();
    let ry_lhs = rng.gen::<f64>();
    let rz_lhs = rng.gen::<f64>();

    let rx_rhs = rng.gen::<f64>();
    let ry_rhs = rng.gen::<f64>();
    let rz_rhs = rng.gen::<f64>();

    let rx_result = rx_lhs * rx_rhs;
    let ry_result = ry_lhs * ry_rhs;
    let rz_result = rz_lhs * rz_rhs;

    let lhs = Vector3D {
        X: rx_lhs,
        Y: ry_lhs,
        Z: rz_lhs,
    };
    let rhs = Vector3D {
        X: rx_rhs,
        Y: ry_rhs,
        Z: rz_rhs,
    };

    let result = lhs * rhs;

    assert_eq!(rx_result, result.X);
    assert_eq!(ry_result, result.Y);
    assert_eq!(rz_result, result.Z);
}

#[test]
fn vector3d_division() {
    let mut rng = rand::thread_rng();

    let rx_lhs = rng.gen::<f64>();
    let ry_lhs = rng.gen::<f64>();
    let rz_lhs = rng.gen::<f64>();

    let rx_rhs = rng.gen::<f64>();
    let ry_rhs = rng.gen::<f64>();
    let rz_rhs = rng.gen::<f64>();

    let rx_result = rx_lhs / rx_rhs;
    let ry_result = ry_lhs / ry_rhs;
    let rz_result = rz_lhs / rz_rhs;

    let lhs = Vector3D {
        X: rx_lhs,
        Y: ry_lhs,
        Z: rz_lhs,
    };
    let rhs = Vector3D {
        X: rx_rhs,
        Y: ry_rhs,
        Z: rz_rhs,
    };

    let result = lhs / rhs;

    assert_eq!(rx_result, result.X);
    assert_eq!(ry_result, result.Y);
    assert_eq!(rz_result, result.Z);
}
