From c9a9cad256b930a3a31311b1cbbba58268aaa102 Mon Sep 17 00:00:00 2001 From: Marckvdv Date: Mon, 3 Oct 2016 13:20:57 +0200 Subject: [PATCH] Added tests for the added cast functions of matrix and point. --- tests/matrix.rs | 27 +++++++++++++++++++++++++++ tests/point.rs | 9 ++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/matrix.rs b/tests/matrix.rs index f888f08..fc3cda3 100644 --- a/tests/matrix.rs +++ b/tests/matrix.rs @@ -704,6 +704,33 @@ pub mod matrix4 { assert_eq!(res, Vector4::new(1., 2., 3., 1.)); } + #[test] + fn test_cast() { + assert_ulps_eq!(Matrix2::new(0.2f64, 1.5, 4.7, 2.3).cast(), Matrix2::new(0.2f32, 1.5, 4.7, 2.3)); + assert_ulps_eq!(Matrix3::new( + 0.2f64, 1.5, 4.7, + 2.3, 5.7, 2.1, + 4.6, 5.2, 6.6, + ).cast(), Matrix3::new( + 0.2f32, 1.5, 4.7, + 2.3, 5.7, 2.1, + 4.6, 5.2, 6.6, + )); + + assert_ulps_eq!(Matrix4::new( + 0.2f64, 1.5, 4.7, 2.5, + 2.3, 5.7, 2.1, 1.1, + 4.6, 5.2, 6.6, 0.2, + 3.2, 1.8, 0.4, 2.9, + ).cast(), Matrix4::new( + 0.2f32, 1.5, 4.7, 2.5, + 2.3, 5.7, 2.1, 1.1, + 4.6, 5.2, 6.6, 0.2, + 3.2, 1.8, 0.4, 2.9, + )); + + } + mod from { use cgmath::*; diff --git a/tests/point.rs b/tests/point.rs index dc896d7..0078189 100644 --- a/tests/point.rs +++ b/tests/point.rs @@ -17,7 +17,7 @@ extern crate approx; extern crate cgmath; -use cgmath::{Point2, Point3}; +use cgmath::{Point1, Point2, Point3}; macro_rules! impl_test_mul { ($PointN:ident { $($field:ident),+ }, $s:expr, $v:expr) => ( @@ -74,3 +74,10 @@ fn test_rem() { impl_test_rem!(Point3 { x, y, z }, 2.0f32, Point3::new(2.0f32, 4.0, 6.0)); impl_test_rem!(Point2 { x, y }, 2.0f32, Point2::new(2.0f32, 4.0)); } + +#[test] +fn test_cast() { + assert_ulps_eq!(Point1::new(0.9f64).cast(), Point1::new(0.9f32)); + assert_ulps_eq!(Point2::new(0.9f64, 1.5).cast(), Point2::new(0.9f32, 1.5)); + assert_ulps_eq!(Point3::new(1.0f64, 2.4, -3.13).cast(), Point3::new(1.0f32, 2.4, -3.13)); +}