From 0e809e78c5c0a1268af391070abb1cf41faa6453 Mon Sep 17 00:00:00 2001 From: Augusto Date: Mon, 28 Dec 2020 21:11:15 +0000 Subject: [PATCH] Add subject and test of the exercise `closures` --- rust/tests/closures_test/Cargo.lock | 12 ++++++++++ rust/tests/closures_test/Cargo.toml | 10 +++++++++ rust/tests/closures_test/src/main.rs | 28 +++++++++++++++++++++++ subjects/closures/README.md | 33 ++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 rust/tests/closures_test/Cargo.lock create mode 100644 rust/tests/closures_test/Cargo.toml create mode 100644 rust/tests/closures_test/src/main.rs create mode 100644 subjects/closures/README.md diff --git a/rust/tests/closures_test/Cargo.lock b/rust/tests/closures_test/Cargo.lock new file mode 100644 index 000000000..4151173cb --- /dev/null +++ b/rust/tests/closures_test/Cargo.lock @@ -0,0 +1,12 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "closures" +version = "0.1.0" + +[[package]] +name = "closures_test" +version = "0.1.0" +dependencies = [ + "closures", +] diff --git a/rust/tests/closures_test/Cargo.toml b/rust/tests/closures_test/Cargo.toml new file mode 100644 index 000000000..064a1c7ee --- /dev/null +++ b/rust/tests/closures_test/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "closures_test" +version = "0.1.0" +authors = ["Augusto "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +closures = { path = "../../../../rust-piscine-solutions/closures"} diff --git a/rust/tests/closures_test/src/main.rs b/rust/tests/closures_test/src/main.rs new file mode 100644 index 000000000..d4c63e016 --- /dev/null +++ b/rust/tests/closures_test/src/main.rs @@ -0,0 +1,28 @@ +// Using closures and iterators create a function, +// first_fifty_even_square() that returns the +// first 50 pair numbers squares that it's [4, 16, 36, ..., 10000]. + +use closures::*; + +fn main() { + println!("Hello, world!"); + let v1 = first_fifty_even_square(); + + println!("All elements in {:?}, len = {}", v1, v1.len()); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test() { + let v1 = vec![ + 4, 16, 36, 64, 100, 144, 196, 256, 324, 400, 484, 576, 676, 784, 900, 1024, 1156, 1296, + 1444, 1600, 1764, 1936, 2116, 2304, 2500, 2704, 2916, 3136, 3364, 3600, 3844, 4096, + 4356, 4624, 4900, 5184, 5476, 5776, 6084, 6400, 6724, 7056, 7396, 7744, 8100, 8464, + 8836, 9216, 9604, 10000, + ]; + assert_eq!(v1, first_fifty_even_square()); + } +} diff --git a/subjects/closures/README.md b/subjects/closures/README.md new file mode 100644 index 000000000..6a34dd26d --- /dev/null +++ b/subjects/closures/README.md @@ -0,0 +1,33 @@ +## closures + +### Instructions + +Using closures and iterators create a function, `first_fifty_even_square` that returns the first 50 + +### Expected Functions + +```rust +fn first_fifty_even_square() -> Vec { +} +``` + +### Usage + +Here is a program to test your function. + +```rust +fn main() { + println!("Hello, world!"); + let v1 = first_fifty_even_square(); + + println!("All elements in {:?}, len = {}", v1, v1.len()); +} +``` + +And its output + +```console +student@ubuntu:~/[[ROOT]]/test$ cargo run +All elements in [4, 16, 36, ..., 10000], len = 50 +student@ubuntu:~/[[ROOT]]/test$ +```