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 authored and taiki-e committed Oct 26, 2023
1 parent 1acbd8f commit 43c0c5f
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 @@ -535,3 +535,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 any = st.any(is_even).await;
assert!(!any);

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 43c0c5f

Please sign in to comment.