diff --git a/agb/src/number.rs b/agb/src/number.rs index da707185..d3c2b27b 100644 --- a/agb/src/number.rs +++ b/agb/src/number.rs @@ -555,6 +555,32 @@ fn test_vector_multiplication_and_division(_gba: &mut super::Gba) { assert_eq!(a, c); } +#[cfg(feature = "alloc")] +mod formatting_tests { + use super::Num; + use alloc::format; + + #[test_case] + fn formats_numbers_correctly(_gba: &mut crate::Gba) { + let a = Num::::new(-4i32); + + assert_eq!(format!("{}", a), "-4"); + } + + #[test_case] + fn formats_fractions_correctly(_gba: &mut crate::Gba) { + let a = Num::::new(5); + let two = Num::::new(4); + let minus_one = Num::::new(-1); + + let b: Num = a / two; + let c: Num = b * minus_one; + + assert_eq!(format!("{}", b), "1.25"); + assert_eq!(format!("{}", c), "-1.25"); + } +} + impl AddAssign for Vector2D { fn add_assign(&mut self, rhs: Self) { *self = *self + rhs;