Skip to content

Commit 4d31b14

Browse files
committed
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.
1 parent a2bae3b commit 4d31b14

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

units/src/amount/tests.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,14 @@ fn sanity_check() {
5252

5353
#[test]
5454
fn check_if_num_is_too_precise() {
55-
assert_eq!(is_too_precise("1234", 3).unwrap(), 3);
56-
assert_eq!(is_too_precise("1234.1234", 3).unwrap(), 3);
55+
// Has decimal, not too precise
56+
assert_eq!(is_too_precise("1234.5678", 4), Some(0));
57+
// Has decimal, is too precise
58+
assert_eq!(is_too_precise("1234.5678", 3), Some(3));
59+
// No decimal, not too precise
60+
assert_eq!(is_too_precise("1234", 4), Some(0));
61+
// No decimal, is too precise
62+
assert_eq!(is_too_precise("1234", 2), Some(3));
5763
}
5864

5965
#[test]

0 commit comments

Comments
 (0)