Skip to content

Commit

Permalink
Add tests for StreamExt::all and StreamExt::any
Browse files Browse the repository at this point in the history
  • Loading branch information
cstyles committed Oct 22, 2023
1 parent 32a8717 commit 631a25e
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions futures/tests/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,43 @@ fn select_with_strategy_doesnt_terminate_early() {
assert_eq!(count.get(), times_should_poll + 1);
}
}

async fn is_even(number: u8) -> bool {
number % 2 == 0
}

#[test]
fn all() {
block_on(async {
let empty: [u8; 0] = [];
let st = stream::iter(empty);
let all = st.all(is_even).await;
assert!(all);

let st = stream::iter([2, 4, 6, 8]);
let all = st.all(is_even).await;
assert!(all);

let st = stream::iter([2, 3, 4]);
let all = st.all(is_even).await;
assert!(!all);
});
}

#[test]
fn any() {
block_on(async {
let empty: [u8; 0] = [];
let st = stream::iter(empty);
let all = st.any(is_even).await;
assert!(!all);

let st = stream::iter([1, 2, 3]);
let any = st.any(is_even).await;
assert!(any);

let st = stream::iter([1, 3, 5]);
let any = st.any(is_even).await;
assert!(!any);
});
}

0 comments on commit 631a25e

Please sign in to comment.