From ed08e322147feb27c9cb6c78db3e9a30164ad0e6 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 11 Mar 2021 21:27:05 +0000 Subject: [PATCH] zcoord: plus_offset: Check both ways Signed-off-by: Ian Jackson --- base/zcoord.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/base/zcoord.rs b/base/zcoord.rs index 0f955f6c..b9133372 100644 --- a/base/zcoord.rs +++ b/base/zcoord.rs @@ -967,12 +967,15 @@ mod test { #[test] fn plus_offset() { - let z: ZCoord = "3o00000000".parse().unwrap(); - assert_eq!(z.plus_offset(0).unwrap(), - "3o00000000_0000004000".parse().unwrap()); - assert_eq!(z.plus_offset(1).unwrap(), - "3o00000000_000000c000".parse().unwrap()); - assert_eq!(z.plus_offset(0xffffffff).unwrap(), - "3o00000000_vvvvvvs000".parse().unwrap()); + fn chk(off: u32, s: &str) { + let z: ZCoord = "3o00000000".parse().unwrap(); + let p = z.plus_offset(off).unwrap(); + assert_eq!(s, format!("{}", &p)); + assert_eq!(p, s.parse().unwrap()); + } + + chk( 0, "3o00000000_0000004000"); + chk( 1, "3o00000000_000000c000"); + chk(0xffffffff, "3o00000000_vvvvvvs000"); } } -- 2.30.2