Skip to content

Commit e6ea5f4

Browse files
committed
Add missing SignedAmount tests
There were some tests for NumOpResult that were only done for Amount. This was caught by the mutation testing. Add the SignedAmount tests as well.
1 parent f808546 commit e6ea5f4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

units/src/amount/result.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,28 @@ mod tests {
349349
let sum: NumOpResult<SignedAmount> = amounts.into_iter().sum();
350350
assert_eq!(sum, NumOpResult::Valid(SignedAmount::from_sat_i32(250)));
351351
}
352+
353+
#[test]
354+
fn test_sum_signed_amount_results_with_references() {
355+
let amounts = [
356+
NumOpResult::Valid(SignedAmount::from_sat_i32(100)),
357+
NumOpResult::Valid(SignedAmount::from_sat_i32(-50)),
358+
NumOpResult::Valid(SignedAmount::from_sat_i32(200)),
359+
];
360+
361+
let sum: NumOpResult<SignedAmount> = amounts.iter().sum();
362+
assert_eq!(sum, NumOpResult::Valid(SignedAmount::from_sat_i32(250)));
363+
}
364+
365+
#[test]
366+
fn test_sum_signed_amount_with_error_propagation() {
367+
let amounts = [
368+
NumOpResult::Valid(SignedAmount::from_sat_i32(100)),
369+
NumOpResult::Error(NumOpError::while_doing(MathOp::Add)),
370+
NumOpResult::Valid(SignedAmount::from_sat_i32(200)),
371+
];
372+
373+
let sum: NumOpResult<SignedAmount> = amounts.into_iter().sum();
374+
assert!(matches!(sum, NumOpResult::Error(_)));
375+
}
352376
}

0 commit comments

Comments
 (0)