From d22ad76ca83acda1428829173451eee0221f685a Mon Sep 17 00:00:00 2001 From: Pazzaz Date: Sat, 16 Jun 2018 20:19:19 +0200 Subject: Optimize sum of Durations by using custom function --- src/libcore/tests/time.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/libcore/tests') diff --git a/src/libcore/tests/time.rs b/src/libcore/tests/time.rs index df139965753..466f28f0ef0 100644 --- a/src/libcore/tests/time.rs +++ b/src/libcore/tests/time.rs @@ -161,6 +161,20 @@ fn checked_div() { assert_eq!(Duration::new(2, 0).checked_div(0), None); } +#[test] +fn correct_sum() { + let durations = [ + Duration::new(1, 999_999_999), + Duration::new(2, 999_999_999), + Duration::new(0, 999_999_999), + Duration::new(0, 999_999_999), + Duration::new(0, 999_999_999), + Duration::new(5, 0), + ]; + let sum = durations.iter().sum::(); + assert_eq!(sum, Duration::new(1+2+5+4, 1_000_000_000 - 5)); +} + #[test] fn debug_formatting_extreme_values() { assert_eq!( -- cgit 1.4.1-3-g733a5