mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-05 17:53:29 +02:00
Clean up and unify exercises
This commit is contained in:
@@ -1,8 +1,3 @@
|
||||
// threads3.rs
|
||||
//
|
||||
// Execute `rustlings hint threads3` or use the `hint` watch subcommand for a
|
||||
// hint.
|
||||
|
||||
use std::sync::mpsc;
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
@@ -42,20 +37,29 @@ fn send_tx(q: Queue, tx: mpsc::Sender<u32>) -> () {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn main() {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let queue = Queue::new();
|
||||
let queue_length = queue.length;
|
||||
|
||||
send_tx(queue, tx);
|
||||
|
||||
let mut total_received: u32 = 0;
|
||||
for received in rx {
|
||||
println!("Got: {}", received);
|
||||
total_received += 1;
|
||||
}
|
||||
|
||||
println!("total numbers received: {}", total_received);
|
||||
assert_eq!(total_received, queue_length)
|
||||
// You can optionally experiment here.
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn threads3() {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let queue = Queue::new();
|
||||
let queue_length = queue.length;
|
||||
|
||||
send_tx(queue, tx);
|
||||
|
||||
let mut total_received: u32 = 0;
|
||||
for received in rx {
|
||||
println!("Got: {}", received);
|
||||
total_received += 1;
|
||||
}
|
||||
|
||||
println!("total numbers received: {}", total_received);
|
||||
assert_eq!(total_received, queue_length)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user