From: Ian Jackson Date: Thu, 11 Mar 2021 21:27:05 +0000 (+0000) Subject: zcoord: plus_offset: Check both ways X-Git-Tag: otter-0.4.0~140 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=ed08e322147feb27c9cb6c78db3e9a30164ad0e6;p=otter.git zcoord: plus_offset: Check both ways Signed-off-by: Ian Jackson --- 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"); } }