Merge pull request #1641 from mo8it/move-semantics5-test

Convert exercises with assertions to tests
This commit is contained in:
liv 2023-09-06 09:31:46 +02:00 committed by GitHub
commit 4d04aad890
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 5 deletions

View File

@ -11,6 +11,7 @@
// I AM NOT DONE // I AM NOT DONE
#[test]
fn main() { fn main() {
let my_fav_fruits = vec!["banana", "custard apple", "avocado", "peach", "raspberry"]; let my_fav_fruits = vec!["banana", "custard apple", "avocado", "peach", "raspberry"];

View File

@ -8,6 +8,7 @@
// I AM NOT DONE // I AM NOT DONE
#[test]
fn main() { fn main() {
let mut x = 100; let mut x = 100;
let y = &mut x; let y = &mut x;

View File

@ -35,6 +35,7 @@ impl Planet {
} }
} }
#[test]
fn main() { fn main() {
let sun = Rc::new(Sun {}); let sun = Rc::new(Sun {});
println!("reference count = {}", Rc::strong_count(&sun)); // 1 reference println!("reference count = {}", Rc::strong_count(&sun)); // 1 reference

View File

@ -48,6 +48,7 @@ fn send_tx(q: Queue, tx: mpsc::Sender<u32>) -> () {
}); });
} }
#[test]
fn main() { fn main() {
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();
let queue = Queue::new(); let queue = Queue::new();

View File

@ -337,7 +337,7 @@ So the end goal is to:
[[exercises]] [[exercises]]
name = "move_semantics5" name = "move_semantics5"
path = "exercises/move_semantics/move_semantics5.rs" path = "exercises/move_semantics/move_semantics5.rs"
mode = "compile" mode = "test"
hint = """ hint = """
Carefully reason about the range in which each mutable reference is in Carefully reason about the range in which each mutable reference is in
scope. Does it help to update the value of referent (x) immediately after scope. Does it help to update the value of referent (x) immediately after
@ -827,7 +827,7 @@ https://doc.rust-lang.org/stable/book/ch11-01-writing-tests.html#checking-for-pa
[[exercises]] [[exercises]]
name = "iterators1" name = "iterators1"
path = "exercises/iterators/iterators1.rs" path = "exercises/iterators/iterators1.rs"
mode = "compile" mode = "test"
hint = """ hint = """
Step 1: Step 1:
We need to apply something to the collection `my_fav_fruits` before we start to go through We need to apply something to the collection `my_fav_fruits` before we start to go through
@ -932,7 +932,7 @@ and try other types!
[[exercises]] [[exercises]]
name = "rc1" name = "rc1"
path = "exercises/smart_pointers/rc1.rs" path = "exercises/smart_pointers/rc1.rs"
mode = "compile" mode = "test"
hint = """ hint = """
This is a straightforward exercise to use the Rc<T> type. Each Planet has This is a straightforward exercise to use the Rc<T> type. Each Planet has
ownership of the Sun, and uses Rc::clone() to increment the reference count of the Sun. ownership of the Sun, and uses Rc::clone() to increment the reference count of the Sun.
@ -1021,7 +1021,7 @@ what you've learned :)"""
[[exercises]] [[exercises]]
name = "threads3" name = "threads3"
path = "exercises/threads/threads3.rs" path = "exercises/threads/threads3.rs"
mode = "compile" mode = "test"
hint = """ hint = """
An alternate way to handle concurrency between threads is to use An alternate way to handle concurrency between threads is to use
a mpsc (multiple producer, single consumer) channel to communicate. a mpsc (multiple producer, single consumer) channel to communicate.