From 6ad4bc49999ba6dc65491ed38770c95f5ca4f8c2 Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Wed, 8 May 2024 13:34:39 +0200 Subject: [PATCH] render: Add tests for round_to_i32 --- render/src/matrix.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/render/src/matrix.rs b/render/src/matrix.rs index 914fed7ed..1d3c10e38 100644 --- a/render/src/matrix.rs +++ b/render/src/matrix.rs @@ -957,4 +957,36 @@ mod tests { PointDelta::new(Twips::new(141), Twips::new(-7)), ), ); + + #[test] + fn test_round_to_i32() { + assert_eq!(round_to_i32(0.0), 0); + assert_eq!(round_to_i32(2.0), 2); + assert_eq!(round_to_i32(2.1), 2); + assert_eq!(round_to_i32(2.5), 2); + assert_eq!(round_to_i32(2.9), 3); + assert_eq!(round_to_i32(3.0), 3); + assert_eq!(round_to_i32(3.1), 3); + assert_eq!(round_to_i32(3.5), 4); + assert_eq!(round_to_i32(3.9), 4); + assert_eq!(round_to_i32(4.0), 4); + assert_eq!(round_to_i32(-2.0), -2); + assert_eq!(round_to_i32(-2.1), -2); + assert_eq!(round_to_i32(-2.5), -2); + assert_eq!(round_to_i32(-2.9), -3); + assert_eq!(round_to_i32(-3.0), -3); + assert_eq!(round_to_i32(-3.1), -3); + assert_eq!(round_to_i32(-3.5), -4); + assert_eq!(round_to_i32(-3.9), -4); + assert_eq!(round_to_i32(-4.0), -4); + assert_eq!(round_to_i32(f32::NAN), 0); + assert_eq!(round_to_i32(f32::INFINITY), 0); + assert_eq!(round_to_i32(f32::NEG_INFINITY), 0); + assert_eq!(round_to_i32(-2147483520f32), -2147483520); + assert_eq!(round_to_i32(-2147483648f32), i32::MIN); + assert_eq!(round_to_i32(-2147483904f32), i32::MIN); + assert_eq!(round_to_i32(2147483520f32), 2147483520); + assert_eq!(round_to_i32(2147483648f32), i32::MIN); + assert_eq!(round_to_i32(2147483904f32), i32::MIN); + } }