Skip to content

Commit

Permalink
proptests
Browse files Browse the repository at this point in the history
  • Loading branch information
harryscholes committed Mar 2, 2024
1 parent e58f69d commit 2335f61
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions src/oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,40 @@ impl<T> Receiver<T> {

#[cfg(test)]
mod tests {
use super::*;
use std::thread;

#[test]
fn test_send_receive() {
let (tx, rx) = channel();
use super::*;
use proptest::prelude::*;

assert_eq!(rx.receive(), None);
proptest! {
#[test]
fn test_send_receive(data in any::<String>()) {
let (tx, rx) = channel();

tx.send(0);
prop_assert_eq!(rx.receive(), None);

assert_eq!(rx.receive(), Some(0));
assert_eq!(rx.receive(), None);
}
tx.send(data.clone());

#[test]
fn test_send_receive_thread_safe() {
let (tx, rx) = channel();
prop_assert_eq!(rx.receive(), Some(data));
prop_assert_eq!(rx.receive(), None);
}

thread::spawn(move || {
tx.send(0);
})
.join()
.unwrap();
#[test]
fn test_send_receive_thread_safe(data in any::<String>()) {
let (tx, rx) = channel();

assert_eq!(rx.receive(), Some(0));
assert_eq!(rx.receive(), None);
{
let data = data.clone();

thread::spawn(move || {
tx.send(data);
})
.join()
.unwrap();
}

prop_assert_eq!(rx.receive(), Some(data));
prop_assert_eq!(rx.receive(), None);
}
}
}

0 comments on commit 2335f61

Please sign in to comment.