diff options
| author | bors <bors@rust-lang.org> | 2019-01-30 21:04:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-01-30 21:04:06 +0000 |
| commit | 147311c5fc62537da8eb9c6f69536bec6719d534 (patch) | |
| tree | a0ec71cd427842da687e498f28f983a4cf709498 /src/liballoc/tests | |
| parent | d9a2e3b1ccf16c6d43f56f503bd80c1ad137d523 (diff) | |
| parent | b062b75559c1e6300324193873631e5e7beccfd7 (diff) | |
| download | rust-147311c5fc62537da8eb9c6f69536bec6719d534.tar.gz rust-147311c5fc62537da8eb9c6f69536bec6719d534.zip | |
Auto merge of #57974 - llogiq:vec-deque-try-fold, r=alexcrichton
override `VecDeque`'s `Iter::try_fold` This should improve performance (wherever it is used), but I haven't found the time to benchmark it yet.
Diffstat (limited to 'src/liballoc/tests')
| -rw-r--r-- | src/liballoc/tests/vec_deque.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/liballoc/tests/vec_deque.rs b/src/liballoc/tests/vec_deque.rs index 76831ba65e3..c9d16a06b47 100644 --- a/src/liballoc/tests/vec_deque.rs +++ b/src/liballoc/tests/vec_deque.rs @@ -1433,3 +1433,40 @@ fn test_rotate_right_random() { } } } + +#[test] +fn test_try_fold_empty() { + assert_eq!(Some(0), VecDeque::<u32>::new().iter().try_fold(0, |_, _| None)); +} + +#[test] +fn test_try_fold_none() { + let v: VecDeque<u32> = (0..12).collect(); + assert_eq!(None, v.into_iter().try_fold(0, |a, b| + if b < 11 { Some(a + b) } else { None })); +} + +#[test] +fn test_try_fold_ok() { + let v: VecDeque<u32> = (0..12).collect(); + assert_eq!(Ok::<_, ()>(66), v.into_iter().try_fold(0, |a, b| Ok(a + b))); +} + +#[test] +fn test_try_fold_unit() { + let v: VecDeque<()> = std::iter::repeat(()).take(42).collect(); + assert_eq!(Some(()), v.into_iter().try_fold((), |(), ()| Some(()))); +} + +#[test] +fn test_try_fold_rotated() { + let mut v: VecDeque<_> = (0..12).collect(); + for n in 0..10 { + if n & 1 == 0 { + v.rotate_left(n); + } else { + v.rotate_right(n); + } + assert_eq!(Ok::<_, ()>(66), v.iter().try_fold(0, |a, b| Ok(a + b))); + } +} |
