From 4a064f2e0a1704eaf46e4f68b0c144f83e2ee013 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 5 Oct 2020 19:40:00 +0100 Subject: [PATCH] refactor bigfloat rust tests for add extraction Signed-off-by: Ian Jackson --- src/bigfloat.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/bigfloat.rs b/src/bigfloat.rs index 6ae6080c..6965ad5d 100644 --- a/src/bigfloat.rs +++ b/src/bigfloat.rs @@ -420,13 +420,18 @@ mod test { #[test] fn addition() { - let mut m = Bigfloat::from_str("!0000 ffff_fff0_fff0") - .unwrap().clone_mut(); - let mut a = |rhs| { - m.add(rhs); - format!("{}", m.repack().unwrap()) - }; - assert_eq!(a(0x02), "!0000 ffff_fff2_fff0"); - assert_eq!(a(0x20), "+0000 0000_0012_fff0"); + fn mk(s: &str) -> super::Mutable { bf(s).clone_mut() } + impl Mutable { + fn chk(mut self, rhs: u32, exp: &str) -> Self { + self.add(rhs); + let got = self.repack().unwrap(); + assert_eq!(got.to_string(), exp); + self + } + } + mk("!0000 ffff_fff0_fff0") + .chk(0x02, "!0000 ffff_fff2_fff0") + .chk(0x20, "+0000 0000_0012_fff0") + ; } } -- 2.30.2