diff options
Diffstat (limited to 'src/libcore/tests')
| -rw-r--r-- | src/libcore/tests/iter.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index d880abb181c..814f4ec4ca5 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -1067,6 +1067,14 @@ fn test_iterator_sum_result() { } #[test] +fn test_iterator_sum_option() { + let v: &[Option<i32>] = &[Some(1), Some(2), Some(3), Some(4)]; + assert_eq!(v.iter().cloned().sum::<Option<i32>>(), Some(10)); + let v: &[Option<i32>] = &[Some(1), None, Some(3), Some(4)]; + assert_eq!(v.iter().cloned().sum::<Option<i32>>(), None); +} + +#[test] fn test_iterator_product() { let v: &[i32] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; assert_eq!(v[..4].iter().cloned().product::<i32>(), 0); @@ -1083,6 +1091,14 @@ fn test_iterator_product_result() { } #[test] +fn test_iterator_product_option() { + let v: &[Option<i32>] = &[Some(1), Some(2), Some(3), Some(4)]; + assert_eq!(v.iter().cloned().product::<Option<i32>>(), Some(24)); + let v: &[Option<i32>] = &[Some(1), None, Some(3), Some(4)]; + assert_eq!(v.iter().cloned().product::<Option<i32>>(), None); +} + +#[test] fn test_iterator_max() { let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; assert_eq!(v[..4].iter().cloned().max(), Some(3)); |
