From 6113192e04ee28aa92fa7b7637bf6bccc056b54c Mon Sep 17 00:00:00 2001 From: Sigurd Kolltveit Date: Wed, 15 Feb 2017 19:40:38 +0100 Subject: [PATCH] Add tests for more formatting options --- complex/src/lib.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/complex/src/lib.rs b/complex/src/lib.rs index f942b82..264e353 100644 --- a/complex/src/lib.rs +++ b/complex/src/lib.rs @@ -1246,11 +1246,18 @@ mod test { #[test] fn test_string_formatting() { - let a: Complex64 = Complex::new(1.234567, 123.4567); - assert_eq!(format!("{}", a), "1.234567+123.4567i"); + let a = Complex::new(1.23456, 123.456); + assert_eq!(format!("{}", a), "1.23456+123.456i"); assert_eq!(format!("{:.2}", a), "1.23+123.46i"); assert_eq!(format!("{:.2E}", a), "1.23E0+1.23E2i"); - assert_eq!(format!("{:e}", a), "1.234567e0+1.234567e2i"); + assert_eq!(format!("{:.2e}", a), "1.23e0+1.23e2i"); + + let b = Complex::new(128, 255); + assert_eq!(format!("{:X}", b), "80+FFi"); + assert_eq!(format!("{:#x}", b), "0x80+0xffi"); + assert_eq!(format!("{:+#b}", b), "+0b1000000+0b1111111i"); + assert_eq!(format!("{:+#16o}", b), " +0o200+0o377i"); + assert_eq!(format!("{:+#016x}", b), "+0x00080+0x00ffi"); } #[test]