#![allow(non_snake_case)] extern crate rand; extern crate MBrane; use rand::Rng; use MBrane::ts::Vector4D::*; #[test] fn vector4d_initialization() { let mut rng = rand::thread_rng(); let rx = rng.gen::(); let ry = rng.gen::(); let rz = rng.gen::(); let rt = rng.gen::(); let vector = Vector4D { X: rx, Y: ry, Z: rz, T: rt, }; assert_eq!(rx, vector.X); assert_eq!(ry, vector.Y); assert_eq!(rz, vector.Z); assert_eq!(rt, vector.T); } #[test] fn vector4d_new_initialization() { let mut rng = rand::thread_rng(); let rx = rng.gen::(); let ry = rng.gen::(); let rz = rng.gen::(); let rt = rng.gen::(); let vector = Vector4D::new(rx, ry, rz, rt); assert_eq!(rx, vector.X); assert_eq!(ry, vector.Y); assert_eq!(rz, vector.Z); assert_eq!(rt, vector.T); } #[test] fn vector4d_magnitude() { let mut rng = rand::thread_rng(); let rx = rng.gen::(); let ry = rng.gen::(); let rz = rng.gen::(); let rt = rng.gen::(); let rresult = ((rx * rx) + (ry * ry) + (rz * rz) + (rt * rt)).sqrt(); let vector = Vector4D::new(rx, ry, rz, rt); assert_eq!(rresult, vector.magnitude()); } #[test] fn vector4d_normalization() { let mut rng = rand::thread_rng(); let rx = rng.gen::(); let ry = rng.gen::(); let rz = rng.gen::(); let rt = rng.gen::(); let rxres = rx / ((rx * rx) + (ry * ry) + (rz * rz) + (rt * rt)).sqrt(); let ryres = ry / ((rx * rx) + (ry * ry) + (rz * rz) + (rt * rt)).sqrt(); let rzres = rz / ((rx * rx) + (ry * ry) + (rz * rz) + (rt * rt)).sqrt(); let rtres = rt / ((rx * rx) + (ry * ry) + (rz * rz) + (rt * rt)).sqrt(); let vector = Vector4D::new(rx, ry, rz, rt); let result = vector.normalize(); assert_eq!(rxres, result.X); assert_eq!(ryres, result.Y); assert_eq!(rzres, result.Z); assert_eq!(rtres, result.T); } #[test] fn vector4d_self_normalization() { let mut rng = rand::thread_rng(); let rx = rng.gen::(); let ry = rng.gen::(); let rz = rng.gen::(); let rt = rng.gen::(); let rxres = rx / ((rx * rx) + (ry * ry) + (rz * rz) + (rt * rt)).sqrt(); let ryres = ry / ((rx * rx) + (ry * ry) + (rz * rz) + (rt * rt)).sqrt(); let rzres = rz / ((rx * rx) + (ry * ry) + (rz * rz) + (rt * rt)).sqrt(); let rtres = rt / ((rx * rx) + (ry * ry) + (rz * rz) + (rt * rt)).sqrt(); let mut vector = Vector4D::new(rx, ry, rz, rt); vector.self_normalize(); assert_eq!(rxres, vector.X); assert_eq!(ryres, vector.Y); assert_eq!(rzres, vector.Z); assert_eq!(rtres, vector.T); } #[test] fn vector4d_dot_product() { let mut rng = rand::thread_rng(); let rx_lhs = rng.gen::(); let ry_lhs = rng.gen::(); let rz_lhs = rng.gen::(); let rt_lhs = rng.gen::(); let rx_rhs = rng.gen::(); let ry_rhs = rng.gen::(); let rz_rhs = rng.gen::(); let rt_rhs = rng.gen::(); let result = (rx_lhs * rx_rhs) + (ry_lhs * ry_rhs) + (rz_lhs * rz_rhs) + (rt_lhs * rt_rhs); let vector_lhs = Vector4D::new(rx_lhs, ry_lhs, rz_lhs, rt_lhs); let vector_rhs = Vector4D::new(rx_rhs, ry_rhs, rz_rhs, rt_rhs); assert_eq!(result, vector_lhs.dot(vector_rhs)); } #[test] fn vector4d_addition() { let mut rng = rand::thread_rng(); let rx_lhs = rng.gen::(); let ry_lhs = rng.gen::(); let rz_lhs = rng.gen::(); let rt_lhs = rng.gen::(); let rx_rhs = rng.gen::(); let ry_rhs = rng.gen::(); let rz_rhs = rng.gen::(); let rt_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 rt_result = rt_lhs + rt_rhs; let lhs = Vector4D::new(rx_lhs, ry_lhs, rz_lhs, rt_lhs); let rhs = Vector4D::new(rx_rhs, ry_rhs, rz_rhs, rt_rhs); let result = lhs + rhs; assert_eq!(rx_result, result.X); assert_eq!(ry_result, result.Y); assert_eq!(rz_result, result.Z); assert_eq!(rt_result, result.T); } #[test] fn vector4d_substraction() { let mut rng = rand::thread_rng(); let rx_lhs = rng.gen::(); let ry_lhs = rng.gen::(); let rz_lhs = rng.gen::(); let rt_lhs = rng.gen::(); let rx_rhs = rng.gen::(); let ry_rhs = rng.gen::(); let rz_rhs = rng.gen::(); let rt_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 rt_result = rt_lhs - rt_rhs; let lhs = Vector4D::new(rx_lhs, ry_lhs, rz_lhs, rt_lhs); let rhs = Vector4D::new(rx_rhs, ry_rhs, rz_rhs, rt_rhs); let result = lhs - rhs; assert_eq!(rx_result, result.X); assert_eq!(ry_result, result.Y); assert_eq!(rz_result, result.Z); assert_eq!(rt_result, result.T); } #[test] fn vector4d_multiplication() { let mut rng = rand::thread_rng(); let rx_lhs = rng.gen::(); let ry_lhs = rng.gen::(); let rz_lhs = rng.gen::(); let rt_lhs = rng.gen::(); let rx_rhs = rng.gen::(); let ry_rhs = rng.gen::(); let rz_rhs = rng.gen::(); let rt_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 rt_result = rt_lhs * rt_rhs; let lhs = Vector4D::new(rx_lhs, ry_lhs, rz_lhs, rt_lhs); let rhs = Vector4D::new(rx_rhs, ry_rhs, rz_rhs, rt_rhs); let result = lhs * rhs; assert_eq!(rx_result, result.X); assert_eq!(ry_result, result.Y); assert_eq!(rz_result, result.Z); assert_eq!(rt_result, result.T); } #[test] fn vector4d_division() { let mut rng = rand::thread_rng(); let rx_lhs = rng.gen::(); let ry_lhs = rng.gen::(); let rz_lhs = rng.gen::(); let rt_lhs = rng.gen::(); let rx_rhs = rng.gen::(); let ry_rhs = rng.gen::(); let rz_rhs = rng.gen::(); let rt_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 rt_result = rt_lhs / rt_rhs; let lhs = Vector4D::new(rx_lhs, ry_lhs, rz_lhs, rt_lhs); let rhs = Vector4D::new(rx_rhs, ry_rhs, rz_rhs, rt_rhs); let result = lhs / rhs; assert_eq!(rx_result, result.X); assert_eq!(ry_result, result.Y); assert_eq!(rz_result, result.Z); assert_eq!(rt_result, result.T); }