From 4d31b141a857e4c90a417cc5805105f160846842 Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Wed, 2 Jul 2025 13:29:00 +0100 Subject: [PATCH] Improve is_too_precise test Two of the match arms in `is_too_precise` were untested. Expand the existing test to check all 4 cases. --- units/src/amount/tests.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/units/src/amount/tests.rs b/units/src/amount/tests.rs index 088497504..933ea5aa5 100644 --- a/units/src/amount/tests.rs +++ b/units/src/amount/tests.rs @@ -52,8 +52,14 @@ fn sanity_check() { #[test] fn check_if_num_is_too_precise() { - assert_eq!(is_too_precise("1234", 3).unwrap(), 3); - assert_eq!(is_too_precise("1234.1234", 3).unwrap(), 3); + // Has decimal, not too precise + assert_eq!(is_too_precise("1234.5678", 4), Some(0)); + // Has decimal, is too precise + assert_eq!(is_too_precise("1234.5678", 3), Some(3)); + // No decimal, not too precise + assert_eq!(is_too_precise("1234", 4), Some(0)); + // No decimal, is too precise + assert_eq!(is_too_precise("1234", 2), Some(3)); } #[test]