#![allow(non_snake_case)] extern crate rand; extern crate MBrane; use rand::Rng; use MBrane::ts::Vector3D::*; #[test] fn vector3d_initialization() { let mut rng = rand::thread_rng(); let rx = rng.gen::(); let ry = rng.gen::(); let rz = rng.gen::(); 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::(); let ry = rng.gen::(); let rz = rng.gen::(); let vector = Vector3D::new(rx, ry, rz); assert_eq!(rx, vector.X); assert_eq!(ry, vector.Y); assert_eq!(rz, vector.Z); } #[test] fn vector3d_magnitude() { let mut rng = rand::thread_rng(); let rx = rng.gen::(); let ry = rng.gen::(); let rz = rng.gen::(); let rresult = ((rx * rx) + (ry * ry) + (rz * rz)).sqrt(); let vector = Vector3D::new(rx, ry, rz); assert_eq!(rresult, vector.magnitude()); } #[test] fn vector3d_normalization() { let mut rng = rand::thread_rng(); let rx = rng.gen::(); let ry = rng.gen::(); let rz = rng.gen::(); 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 vector = Vector3D::new(rx, ry, rz); let result = vector.normalize(); assert_eq!(rxres, result.X); assert_eq!(ryres, result.Y); assert_eq!(rzres, result.Z); } #[test] fn vector3d_self_normalization() { let mut rng = rand::thread_rng(); let rx = rng.gen::(); let ry = rng.gen::(); let rz = rng.gen::(); 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::new(rx, ry, rz); vector.self_normalize(); assert_eq!(rxres, vector.X); assert_eq!(ryres, vector.Y); assert_eq!(rzres, vector.Z); } #[test] fn vector3d_dot_product() { let mut rng = rand::thread_rng(); let rx_lhs = rng.gen::(); let ry_lhs = rng.gen::(); let rz_lhs = rng.gen::(); let rx_rhs = rng.gen::(); let ry_rhs = rng.gen::(); let rz_rhs = rng.gen::(); let result = (rx_lhs * rx_rhs) + (ry_lhs * ry_rhs) + (rz_lhs * rz_rhs); let vector_lhs = Vector3D::new(rx_lhs, ry_lhs, rz_lhs); let vector_rhs = Vector3D::new(rx_rhs, ry_rhs, rz_rhs); let res = vector_lhs | vector_rhs; assert_eq!(result, res); } #[test] fn vector3d_addition() { let mut rng = rand::thread_rng(); let rx_lhs = rng.gen::(); let ry_lhs = rng.gen::(); let rz_lhs = rng.gen::(); let rx_rhs = rng.gen::(); let ry_rhs = rng.gen::(); let rz_rhs = rng.gen::(); let rx_result = rx_lhs + rx_rhs; let ry_result = ry_lhs + ry_rhs; let rz_result = rz_lhs + rz_rhs; let lhs = Vector3D::new(rx_lhs, ry_lhs, rz_lhs); let rhs = Vector3D::new(rx_rhs, ry_rhs, 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::(); let ry_lhs = rng.gen::(); let rz_lhs = rng.gen::(); let rx_rhs = rng.gen::(); let ry_rhs = rng.gen::(); let rz_rhs = rng.gen::(); let rx_result = rx_lhs - rx_rhs; let ry_result = ry_lhs - ry_rhs; let rz_result = rz_lhs - rz_rhs; let lhs = Vector3D::new(rx_lhs, ry_lhs, rz_lhs); let rhs = Vector3D::new(rx_rhs, ry_rhs, 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::(); let ry_lhs = rng.gen::(); let rz_lhs = rng.gen::(); let rx_rhs = rng.gen::(); let ry_rhs = rng.gen::(); let rz_rhs = rng.gen::(); let rx_result = rx_lhs * rx_rhs; let ry_result = ry_lhs * ry_rhs; let rz_result = rz_lhs * rz_rhs; let lhs = Vector3D::new(rx_lhs, ry_lhs, rz_lhs); let rhs = Vector3D::new(rx_rhs, ry_rhs, 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::(); let ry_lhs = rng.gen::(); let rz_lhs = rng.gen::(); let rx_rhs = rng.gen::(); let ry_rhs = rng.gen::(); let rz_rhs = rng.gen::(); let rx_result = rx_lhs / rx_rhs; let ry_result = ry_lhs / ry_rhs; let rz_result = rz_lhs / rz_rhs; let lhs = Vector3D::new(rx_lhs, ry_lhs, rz_lhs); let rhs = Vector3D::new(rx_rhs, ry_rhs, 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_dot() { let mut rng = rand::thread_rng(); let rx_lhs = rng.gen::(); let ry_lhs = rng.gen::(); let rz_lhs = rng.gen::(); let rx_rhs = rng.gen::(); let ry_rhs = rng.gen::(); let rz_rhs = rng.gen::(); let result = (rx_lhs * rx_rhs) + (ry_lhs * ry_rhs) + (rz_lhs * rz_rhs); let lhs = Vector3D::new(rx_lhs, ry_lhs, rz_lhs); let rhs = Vector3D::new(rx_rhs, ry_rhs, rz_rhs); let res = lhs | rhs; assert_eq!(result, res); }