forked from root/public
xpetit
3 years ago
256 changed files with 0 additions and 10315 deletions
@ -1,13 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "adding" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "adding_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"adding 0.1.0", |
||||
] |
||||
|
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "adding_test" |
||||
version = "0.1.0" |
||||
authors = ["MSilva95 <miguel-silva98@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
adding = { path = "../../../../rust-piscine-solutions/adding"} |
@ -1,73 +0,0 @@
|
||||
/* |
||||
## adding |
||||
|
||||
### Instructions |
||||
|
||||
Create the function `add_curry` that returns a closure. |
||||
The purpose is to curry the add method to create more variations. |
||||
|
||||
*/ |
||||
use adding::*; |
||||
fn main() { |
||||
let add10 = add_curry(-10); |
||||
let add20 = add_curry(2066); |
||||
let add30 = add_curry(300000); |
||||
|
||||
println!("{}", add10(5)); |
||||
println!("{}", add20(195)); |
||||
println!("{}", add30(5696)); |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
|
||||
#[test] |
||||
fn test_zero() { |
||||
let z = add_curry(0); |
||||
assert_eq!(z(1999), 1999); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_negatives() { |
||||
let neg = add_curry(-10); |
||||
assert_eq!(neg(6), -4); |
||||
assert_eq!(neg(10), 0); |
||||
assert_eq!(neg(600), 590); |
||||
assert_eq!(neg(1000), 990); |
||||
assert_eq!(neg(463), 453); |
||||
assert_eq!(neg(400000000), 399999990); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_add10() { |
||||
let add10 = add_curry(10); |
||||
assert_eq!(add10(6), 16); |
||||
assert_eq!(add10(10), 20); |
||||
assert_eq!(add10(600), 610); |
||||
assert_eq!(add10(1000), 1010); |
||||
assert_eq!(add10(463), 473); |
||||
assert_eq!(add10(400000000), 400000010); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_add250() { |
||||
let add250 = add_curry(250); |
||||
assert_eq!(add250(6), 256); |
||||
assert_eq!(add250(10), 260); |
||||
assert_eq!(add250(600), 850); |
||||
assert_eq!(add250(1000), 1250); |
||||
assert_eq!(add250(463), 713); |
||||
assert_eq!(add250(400000000), 400000250); |
||||
} |
||||
#[test] |
||||
fn test_add3960() { |
||||
let add3960 = add_curry(3960); |
||||
assert_eq!(add3960(6), 3966); |
||||
assert_eq!(add3960(10), 3970); |
||||
assert_eq!(add3960(600), 4560); |
||||
assert_eq!(add3960(1000), 4960); |
||||
assert_eq!(add3960(463), 4423); |
||||
assert_eq!(add3960(400000000), 400003960); |
||||
} |
||||
} |
@ -1,13 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "adding_twice" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "adding_twice_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"adding_twice 0.1.0", |
||||
] |
||||
|
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "adding_twice_test" |
||||
version = "0.1.0" |
||||
authors = ["MSilva95 <miguel-silva98@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
adding_twice = { path = "../../../../rust-piscine-solutions/adding_twice"} |
@ -1,87 +0,0 @@
|
||||
/* |
||||
## adding_twice |
||||
|
||||
### Instructions |
||||
|
||||
In this exercise you will have to reuse your `add_curry` function |
||||
Then you have to complete the function `twice` using closures, this function will |
||||
take a function f(x) as parameter and return a function f(f(x)) |
||||
So, the purpose of this function is to add two times the value in `add_curry`
|
||||
to the original value. |
||||
|
||||
### Notions |
||||
|
||||
- https://doc.rust-lang.org/rust-by-example/fn/hof.html#higher-order-functions
|
||||
*/ |
||||
use adding_twice::*; |
||||
fn main() { |
||||
let add10 = add_curry(10); |
||||
let value = twice(add10); |
||||
println!("The value is {}", value(7)); |
||||
|
||||
let add20 = add_curry(20); |
||||
let value = twice(add20); |
||||
println!("The value is {}", value(7)); |
||||
|
||||
let add30 = add_curry(30); |
||||
let value = twice(add30); |
||||
println!("The value is {}", value(7)); |
||||
|
||||
let neg = add_curry(-32); |
||||
let value = twice(neg); |
||||
println!("{}", value(7)); |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
|
||||
|
||||
#[test] |
||||
fn test_zero_twice() { |
||||
let z = twice(add_curry(0)); |
||||
assert_eq!(z(1902), 1902); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_negative_twice() { |
||||
let neg = twice(add_curry(-32)); |
||||
assert_eq!(neg(6), -58); |
||||
assert_eq!(neg(10), -54); |
||||
assert_eq!(neg(660), 596); |
||||
assert_eq!(neg(1902), 1838); |
||||
assert_eq!(neg(463), 399); |
||||
assert_eq!(neg(400000000), 399999936); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_add10_twice() { |
||||
let value = twice(add_curry(10)); |
||||
assert_eq!(value(6), 26); |
||||
assert_eq!(value(10), 30); |
||||
assert_eq!(value(600), 620); |
||||
assert_eq!(value(1000), 1020); |
||||
assert_eq!(value(463), 483); |
||||
assert_eq!(value(400000000), 400000020); |
||||
} |
||||
#[test] |
||||
fn test_add20_twice() { |
||||
let value = twice(add_curry(20)); |
||||
assert_eq!(value(6), 46); |
||||
assert_eq!(value(10), 50); |
||||
assert_eq!(value(600), 640); |
||||
assert_eq!(value(1000), 1040); |
||||
assert_eq!(value(463), 503); |
||||
assert_eq!(value(400000000), 400000040); |
||||
} |
||||
#[test] |
||||
fn test_add30_twice() { |
||||
let value = twice(add_curry(30)); |
||||
assert_eq!(value(6), 66); |
||||
assert_eq!(value(10), 70); |
||||
assert_eq!(value(600), 660); |
||||
assert_eq!(value(1000), 1060); |
||||
assert_eq!(value(463), 523); |
||||
assert_eq!(value(400000000), 400000060); |
||||
} |
||||
} |
@ -1,93 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "arrange_it" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"jemalloc-ctl", |
||||
"jemallocator", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "arrange_it_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"arrange_it", |
||||
"jemalloc-ctl", |
||||
"jemallocator", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "cc" |
||||
version = "1.0.65" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "95752358c8f7552394baf48cd82695b345628ad3f170d607de3ca03b8dacca15" |
||||
|
||||
[[package]] |
||||
name = "fs_extra" |
||||
version = "1.2.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" |
||||
|
||||
[[package]] |
||||
name = "jemalloc-ctl" |
||||
version = "0.3.3" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "c502a5ff9dd2924f1ed32ba96e3b65735d837b4bfd978d3161b1702e66aca4b7" |
||||
dependencies = [ |
||||
"jemalloc-sys", |
||||
"libc", |
||||
"paste", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "jemalloc-sys" |
||||
version = "0.3.2" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45" |
||||
dependencies = [ |
||||
"cc", |
||||
"fs_extra", |
||||
"libc", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "jemallocator" |
||||
version = "0.3.2" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69" |
||||
dependencies = [ |
||||
"jemalloc-sys", |
||||
"libc", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "libc" |
||||
version = "0.2.80" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" |
||||
|
||||
[[package]] |
||||
name = "paste" |
||||
version = "0.1.18" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880" |
||||
dependencies = [ |
||||
"paste-impl", |
||||
"proc-macro-hack", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "paste-impl" |
||||
version = "0.1.18" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6" |
||||
dependencies = [ |
||||
"proc-macro-hack", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "proc-macro-hack" |
||||
version = "0.5.19" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" |
@ -1,12 +0,0 @@
|
||||
[package] |
||||
name = "arrange_it_test" |
||||
version = "0.1.0" |
||||
authors = ["lee <lee-dasilva@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
jemalloc-ctl = "0.3.3" |
||||
jemallocator = "0.3.2" |
||||
arrange_it = { path = "../../../../rust-piscine-solutions/arrange_it"} |
@ -1,103 +0,0 @@
|
||||
/* |
||||
## arrange_it |
||||
|
||||
### Instructions |
||||
|
||||
Create a function called `arrange_phrase` that takes a string literal as a phrase and returns it organized |
||||
Each word will have a number that indicates the position of that word |
||||
|
||||
### Example |
||||
|
||||
```rust |
||||
``` |
||||
|
||||
> This exercise will test the **heap allocation** of your function! |
||||
> So try your best to allocate the minimum data on the heap! |
||||
|
||||
### Notions |
||||
|
||||
- https://doc.rust-lang.org/1.22.0/book/first-edition/the-stack-and-the-heap.html
|
||||
- https://doc.rust-lang.org/std/primitive.str.html#method.split
|
||||
|
||||
*/ |
||||
|
||||
#[allow(unused_imports)] |
||||
#[global_allocator] |
||||
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; |
||||
#[allow(unused_imports)] |
||||
use arrange_it::*; |
||||
|
||||
#[allow(unused_imports)] |
||||
use jemalloc_ctl::{epoch, stats}; |
||||
|
||||
#[allow(dead_code)] |
||||
fn main() { |
||||
println!("{:?}", arrange_phrase("is2 Thi1s T4est 3a")); |
||||
} |
||||
|
||||
// example of function that works but does not pass the heap test
|
||||
// fn arrange_phrase(phrase: &str) -> String {
|
||||
// let words_nbr = phrase.matches(" ").count() + 1;
|
||||
// let mut result_vec:Vec<String> = vec!["".to_string();words_nbr];
|
||||
// for word in phrase.split_whitespace().into_iter() {
|
||||
// for i in 1..words_nbr+1 {
|
||||
// if word.contains(&i.to_string()){
|
||||
// result_vec[i-1] = word.split(&i.to_string()).collect::<String>();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// result_vec.join(" ")
|
||||
// }
|
||||
|
||||
#[allow(dead_code)] |
||||
fn arrange_phrase_sol(phrase: &str) -> String { |
||||
let nbrs: Vec<&str> = phrase.matches(char::is_numeric).collect(); |
||||
let a = &phrase.replace(char::is_numeric, ""); |
||||
let mut m: Vec<&str> = a.split_whitespace().collect(); |
||||
|
||||
for (i, ele) in nbrs.iter().enumerate() { |
||||
let strs: Vec<&str> = a.split_whitespace().collect(); |
||||
m[ele.parse::<usize>().unwrap() - 1] = strs[i]; |
||||
} |
||||
m.join(" ") |
||||
} |
||||
|
||||
#[test] |
||||
fn test_heap_memory_allocation() { |
||||
// the statistics tracked by jemalloc are cached
|
||||
// The epoch controls when they are refreshed
|
||||
let e = epoch::mib().unwrap(); |
||||
// allocated: number of bytes allocated by the application
|
||||
let allocated = stats::allocated::mib().unwrap(); |
||||
let test_value = "4of Fo1r pe6ople g3ood th5e the2"; |
||||
|
||||
arrange_phrase_sol(test_value); |
||||
// this will advance with the epoch giving the its old value
|
||||
// where we read the updated heap allocation using the `allocated.read()`
|
||||
e.advance().unwrap(); |
||||
let solution = allocated.read().unwrap(); |
||||
|
||||
arrange_phrase(test_value); |
||||
e.advance().unwrap(); |
||||
let student = allocated.read().unwrap(); |
||||
|
||||
assert!( |
||||
student <= solution, |
||||
format!( |
||||
"your heap allocation is {}, and it must be less or equal to {}", |
||||
student, solution |
||||
) |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_function() { |
||||
let cases = vec![ |
||||
"4of Fo1r pe6ople g3ood th5e the2", |
||||
"is2 Thi1s T4est 3a", |
||||
"w7ork t3he a4rt o5f Per1formance is2 a6voiding", |
||||
]; |
||||
for v in cases { |
||||
assert_eq!(arrange_phrase(v), arrange_phrase_sol(v)); |
||||
} |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "arrays" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "arrays_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"arrays", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "arrays_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
arrays = { path = "../../../../rust-piscine-solutions/arrays"} |
@ -1,33 +0,0 @@
|
||||
// Define a function call thirtytwo_tens that returns an array with 32
|
||||
// positions fill with only the value 10: [10, 10, 10, ... 10].len()
|
||||
// = 32
|
||||
|
||||
// Write a function that takes an array of i32 and returns the sum of
|
||||
// the elements (make it work with the main)
|
||||
use arrays::*; |
||||
|
||||
fn main() { |
||||
let a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
||||
let a1: Vec<i32> = (1..11).collect(); |
||||
let b = [5; 10]; |
||||
|
||||
println!("The Sum of the elements in {:?} = {}", a, sum(&a)); |
||||
println!("The Sum of the elements in {:?} = {}", a1, sum(&a1)); |
||||
println!("The Sum of the elements in {:?} = {}", b, sum(&b)); |
||||
println!( |
||||
"Array size {} with only 10's in it {:?}", |
||||
thirtytwo_tens().len(), |
||||
thirtytwo_tens() |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_thirtytwo_tens() { |
||||
assert_eq!(thirtytwo_tens(), [10; 32]); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_sum() { |
||||
let a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
||||
assert_eq!(sum(&a), a.iter().sum()); |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "banner" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "banner_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"banner", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "banner_test" |
||||
version = "0.1.0" |
||||
authors = ["lee <lee-dasilva@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
banner = { path = "../../../../rust-piscine-solutions/banner"} |
@ -1,88 +0,0 @@
|
||||
use std::collections::HashMap; |
||||
use banner::*; |
||||
|
||||
fn main() { |
||||
let mut handler = FlagsHandler { flags: HashMap::new() }; |
||||
|
||||
let d = Flag::opt_flag("division", "divides the values, formula (a / b)"); |
||||
let r = Flag::opt_flag( |
||||
"remainder", |
||||
"remainder of the division between two values, formula (a % b)", |
||||
); |
||||
|
||||
handler.add_flag((d.short_hand, d.long_hand), div); |
||||
handler.add_flag((r.short_hand, r.long_hand), rem); |
||||
|
||||
println!("{:?}", handler.exec_func(("-d".to_string(), "--division".to_string()), &["1.0", "2.0"])); |
||||
// output: "0.5"
|
||||
|
||||
println!("{:?}",handler.exec_func(("-r".to_string(), "--remainder".to_string()), &["2.0", "2.0"])); |
||||
// output: "0.0"
|
||||
|
||||
println!("{:?}",handler.exec_func(("-d".to_string(), "--division".to_string()), &["a", "2.0"])); |
||||
// output: "invalid float literal"
|
||||
|
||||
println!("{:?}",handler.exec_func(("-r".to_string(), "--remainder".to_string()), &["2.0", "fd"])); |
||||
// output: "invalid float literal"
|
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
|
||||
fn init() -> FlagsHandler { |
||||
let d = Flag::opt_flag("division", "divides two numbers"); |
||||
let r = Flag::opt_flag( |
||||
"remainder", |
||||
"gives the remainder of the division between two numbers", |
||||
); |
||||
let mut handler = FlagsHandler { flags: HashMap::new() }; |
||||
|
||||
handler.add_flag((d.short_hand, d.long_hand), div); |
||||
handler.add_flag((r.short_hand, r.long_hand), rem); |
||||
return handler; |
||||
} |
||||
|
||||
#[test] |
||||
fn ok_test() { |
||||
let mut handler = init(); |
||||
assert_eq!( |
||||
handler.exec_func(("-d".to_string(), "--division".to_string()), &["1.0", "2.0"]), |
||||
"0.5" |
||||
); |
||||
assert_eq!( |
||||
handler.exec_func(("-r".to_string(), "--remainder".to_string()), &["2.0", "2.0"]), |
||||
"0" |
||||
); |
||||
assert_eq!( |
||||
handler.exec_func(("-d".to_string(), "--division".to_string()), &["12.323", "212.32"]), |
||||
"0.05803975" |
||||
); |
||||
assert_eq!( |
||||
handler.exec_func(("-r".to_string(), "--remainder".to_string()), &["12.323", "212.32"]), |
||||
"12.323" |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
fn error_test() { |
||||
let mut handler = init(); |
||||
assert_eq!( |
||||
handler.exec_func(("-d".to_string(), "--division".to_string()), &["a", "2.0"]), |
||||
"invalid float literal" |
||||
); |
||||
assert_eq!( |
||||
handler.exec_func(("-r".to_string(), "--remainder".to_string()), &["2.0", "f"]), |
||||
"invalid float literal" |
||||
); |
||||
assert_eq!( |
||||
handler.exec_func(("-d".to_string(), "--division".to_string()), &["1.0", "0.0"]), |
||||
"inf" |
||||
); |
||||
assert_eq!( |
||||
handler.exec_func(("-r".to_string(), "--remainder".to_string()), &["2.0", "0.0"]), |
||||
"NaN" |
||||
); |
||||
} |
||||
} |
||||
|
@ -1,91 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "bigger" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"rand", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "bigger_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"bigger", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "cfg-if" |
||||
version = "0.1.10" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" |
||||
|
||||
[[package]] |
||||
name = "getrandom" |
||||
version = "0.1.14" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" |
||||
dependencies = [ |
||||
"cfg-if", |
||||
"libc", |
||||
"wasi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "libc" |
||||
version = "0.2.74" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10" |
||||
|
||||
[[package]] |
||||
name = "ppv-lite86" |
||||
version = "0.2.8" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" |
||||
|
||||
[[package]] |
||||
name = "rand" |
||||
version = "0.7.3" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" |
||||
dependencies = [ |
||||
"getrandom", |
||||
"libc", |
||||
"rand_chacha", |
||||
"rand_core", |
||||
"rand_hc", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand_chacha" |
||||
version = "0.2.2" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" |
||||
dependencies = [ |
||||
"ppv-lite86", |
||||
"rand_core", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand_core" |
||||
version = "0.5.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" |
||||
dependencies = [ |
||||
"getrandom", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand_hc" |
||||
version = "0.2.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" |
||||
dependencies = [ |
||||
"rand_core", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "wasi" |
||||
version = "0.9.0+wasi-snapshot-preview1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "bigger_test" |
||||
version = "0.1.0" |
||||
authors = ["MSilva95 <miguel-silva98@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
bigger = { path = "../../../../rust-piscine-solutions/bigger"} |
@ -1,39 +0,0 @@
|
||||
// Create the function `bigger` that gets the biggest positive number in the `HashMap`
|
||||
|
||||
use bigger::*; |
||||
use std::collections::HashMap; |
||||
|
||||
fn main() { |
||||
let mut hash = HashMap::new(); |
||||
hash.insert("Daniel", 122); |
||||
hash.insert("Ashley", 333); |
||||
hash.insert("Katie", 334); |
||||
hash.insert("Robert", 14); |
||||
|
||||
println!( |
||||
"The biggest of the elements in the HashMap is {}", |
||||
bigger(hash) |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_positive() { |
||||
let mut f = HashMap::new(); |
||||
f.insert("Daniel", 12); |
||||
f.insert("Ashley", 333); |
||||
f.insert("Katie", 334); |
||||
f.insert("Robert", 14); |
||||
|
||||
assert_eq!(334, bigger(f)); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_negative() { |
||||
let mut f = HashMap::new(); |
||||
f.insert("Daniel", 41758712); |
||||
f.insert("Ashley", 54551444); |
||||
f.insert("Katie", 575556334); |
||||
f.insert("Robert", 574148); |
||||
|
||||
assert_eq!(575556334, bigger(f)); |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "blood_types" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "blood_types_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"blood_types", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "blood_types_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
blood_types = { path = "../../../../rust-piscine-solutions/blood_types"} |
@ -1,187 +0,0 @@
|
||||
// In this exercise you will create a model of and gives an API to
|
||||
// deal with blood types
|
||||
|
||||
// Start creating the data representation of the blood types
|
||||
// Create the enumerator `Antigen` that has 4 possibilities: A, B, O and AB
|
||||
// And the enumerator `RhFactor` that has two possible values: Positive
|
||||
// and Negative
|
||||
|
||||
// After, create the struct BloodType that contains two fields with the
|
||||
// names antigen and rh_factor
|
||||
|
||||
// To provide a simple way to create blood types implement the trait
|
||||
// FromStr for BloodType (which will allow us to use the `parse`
|
||||
// method and the associated function from_str, so we can do:
|
||||
// ```rust
|
||||
// let a_neg: BloodType = "A-".parse();
|
||||
// ```
|
||||
//)
|
||||
|
||||
// Implement the std::cmp::Ord trait to make possible to sort a vector
|
||||
// or array of BloodType's
|
||||
|
||||
// Implement the trait std::Debug for BloodType allowing to print a
|
||||
// vector such as [BloodType { antigen: A, rh_factor: Positive},
|
||||
// BloodType{ antigen: B, rh_factor: Negative}] as [ A+, A-] using the
|
||||
// formatting {:?}
|
||||
|
||||
// Write three methods for BloodType:
|
||||
// - can_receive_from(&self, other: BloodType) -> bool {}: which
|
||||
// returns true if self can receive blood from `other` blood type
|
||||
// - donors(&self) -> Vec<BloodType>: which returns
|
||||
// all the blood types that can give blood to self
|
||||
// - recipients(&self) -> Vec<BloodType>: which returns all the blood
|
||||
// types that can receive blood from self
|
||||
|
||||
#[allow(unused_imports)] |
||||
use blood_types::{Antigen, BloodType, RhFactor}; |
||||
|
||||
fn main() { |
||||
let blood_type: BloodType = "O+".parse().unwrap(); |
||||
println!("recipients of O+ {:?}", blood_type.recipients()); |
||||
println!("donors of O+ {:?}", blood_type.donors()); |
||||
let another_blood_type: BloodType = "A-".parse().unwrap(); |
||||
println!( |
||||
"donors of O+ can receive from {:?} {:?}", |
||||
&another_blood_type, |
||||
blood_type.can_receive_from(&another_blood_type) |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
fn compatible_ab_neg_with_a_pos() { |
||||
let blood_type: BloodType = "AB-".parse().unwrap(); |
||||
let other_bt: BloodType = "A+".parse().unwrap(); |
||||
assert!(!blood_type.can_receive_from(&other_bt)); |
||||
} |
||||
|
||||
#[test] |
||||
fn compatible_a_neg_with_a_pos() { |
||||
let blood_type: BloodType = "A-".parse().unwrap(); |
||||
let other_bt: BloodType = "A+".parse().unwrap(); |
||||
assert!(!blood_type.can_receive_from(&other_bt)); |
||||
} |
||||
|
||||
#[test] |
||||
fn compatible_a_neg_with_ab_neg() { |
||||
let blood_type: BloodType = "AB-".parse().unwrap(); |
||||
let other_bt: BloodType = "A-".parse().unwrap(); |
||||
assert!(blood_type.can_receive_from(&other_bt)); |
||||
} |
||||
|
||||
#[test] |
||||
fn compatible_ab_neg_with_o_pos() { |
||||
let blood_type: BloodType = "AB-".parse().unwrap(); |
||||
let other_bt: BloodType = "O+".parse().unwrap(); |
||||
assert!(!blood_type.can_receive_from(&other_bt)); |
||||
} |
||||
|
||||
#[test] |
||||
fn compatible_ab_pos_with_o_pos() { |
||||
let blood_type: BloodType = "AB+".parse().unwrap(); |
||||
let other_bt: BloodType = "O+".parse().unwrap(); |
||||
assert!(blood_type.can_receive_from(&other_bt)); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_compatible_ab_neg_with_o_neg() { |
||||
let blood_type: BloodType = "AB-".parse().unwrap(); |
||||
let other_bt: BloodType = "O-".parse().unwrap(); |
||||
assert!(blood_type.can_receive_from(&other_bt)); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_antigen_ab_from_str() { |
||||
let blood = "AB+"; |
||||
let blood_type: BloodType = blood.parse().unwrap(); |
||||
assert_eq!(blood_type.antigen, Antigen::AB); |
||||
assert_eq!(blood_type.rh_factor, RhFactor::Positive); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_antigen_a_from_str() { |
||||
let blood = "A-"; |
||||
let blood_type = blood.parse::<BloodType>().unwrap(); |
||||
assert_eq!(blood_type.antigen, Antigen::A); |
||||
assert_eq!(blood_type.rh_factor, RhFactor::Negative); |
||||
} |
||||
|
||||
#[test] |
||||
#[should_panic] |
||||
fn test_unexistent_blood_type() { |
||||
let _blood_type: BloodType = "AO-".parse().unwrap(); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_donors() { |
||||
let mut givers = "AB+".parse::<BloodType>().unwrap().donors(); |
||||
println!("Before sorting {:?}", &givers); |
||||
givers.sort(); |
||||
println!("{:?}", &givers); |
||||
let mut expected = vec![ |
||||
"AB-".parse::<BloodType>().unwrap(), |
||||
"A-".parse().unwrap(), |
||||
"B-".parse().unwrap(), |
||||
"O-".parse().unwrap(), |
||||
"AB+".parse().unwrap(), |
||||
"A+".parse().unwrap(), |
||||
"B+".parse().unwrap(), |
||||
"O+".parse().unwrap(), |
||||
]; |
||||
expected.sort(); |
||||
assert_eq!(givers, expected); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_a_neg_donors() { |
||||
let mut givers = "A-".parse::<BloodType>().unwrap().donors(); |
||||
givers.sort(); |
||||
let mut expected: Vec<BloodType> = vec!["A-".parse().unwrap(), "O-".parse().unwrap()]; |
||||
expected.sort(); |
||||
assert_eq!(givers, expected); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_o_neg_donors() { |
||||
let mut givers = "O-".parse::<BloodType>().unwrap().donors(); |
||||
givers.sort(); |
||||
let mut expected: Vec<BloodType> = vec!["O-".parse().unwrap()]; |
||||
expected.sort(); |
||||
assert_eq!(givers, expected); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_ab_pos_recipients() { |
||||
let mut recipients: Vec<BloodType> = "AB+".parse::<BloodType>().unwrap().recipients(); |
||||
recipients.sort(); |
||||
let mut expected: Vec<BloodType> = vec!["AB+".parse().unwrap()]; |
||||
expected.sort(); |
||||
assert_eq!(recipients, expected); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_a_neg_recipients() { |
||||
let mut recipients = "A-".parse::<BloodType>().unwrap().recipients(); |
||||
recipients.sort(); |
||||
let mut expected: Vec<BloodType> = vec![ |
||||
"A-".parse().unwrap(), |
||||
"AB+".parse().unwrap(), |
||||
"A+".parse().unwrap(), |
||||
"AB-".parse().unwrap(), |
||||
]; |
||||
expected.sort(); |
||||
assert_eq!(recipients, expected); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_output() { |
||||
let blood_type: BloodType = "O+".parse().unwrap(); |
||||
println!("recipients of O+ {:?}", blood_type.recipients()); |
||||
println!("donors of O+ {:?}", blood_type.donors()); |
||||
let another_blood_type: BloodType = "A-".parse().unwrap(); |
||||
println!( |
||||
"donors of O+ can receive from {:?} {:?}", |
||||
&another_blood_type, |
||||
blood_type.can_receive_from(&another_blood_type) |
||||
); |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "borrow_box" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "borrow_box_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"borrow_box", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "borrow_box_test" |
||||
version = "0.1.0" |
||||
authors = ["lee <lee-dasilva@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
borrow_box = { path = "../../../../rust-piscine-solutions/borrow_box"} |
@ -1,91 +0,0 @@
|
||||
use borrow_box::*; |
||||
|
||||
fn main() { |
||||
let mut game = Game::new(0, String::from("Joao"), String::from("Susana"), 5); |
||||
println!("{:?}", game.read_winner()); |
||||
// output : ("Same score! tied", 0)
|
||||
|
||||
game.update_score(String::from("Joao")); |
||||
game.update_score(String::from("Joao")); |
||||
game.update_score(String::from("Susana")); |
||||
game.update_score(String::from("Susana")); |
||||
println!("{:?}", game.read_winner()); |
||||
// output : ("Same score! tied", 2)
|
||||
|
||||
game.update_score(String::from("Joao")); |
||||
// this one will not count because it already 5 games played, the nbr_of_games
|
||||
game.update_score(String::from("Susana")); |
||||
|
||||
println!("{:?}", game.read_winner()); |
||||
// output : ("Joao", 3)
|
||||
|
||||
println!("{:?}", game.delete()); |
||||
// output : "game deleted: id -> 0"
|
||||
|
||||
// game.read_winner();
|
||||
// this will give error
|
||||
// because the game was dropped, no longer exists on the heap
|
||||
} |
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
|
||||
fn create_games() -> Vec<Box<Game>> { |
||||
vec![ |
||||
Game::new(0, String::from("player1"), String::from("player2"), 1), |
||||
Game::new(1, String::from("Alice"), String::from("Mark"), 3), |
||||
Game::new(2, String::from("Jack"), String::from("Miller"), 5) |
||||
] |
||||
} |
||||
|
||||
#[test] |
||||
fn test_create() { |
||||
let games = create_games(); |
||||
assert_eq!(*games[0], Game {id: 0, p1: (String::from("player1"), 0), p2: (String::from("player2"), 0), nbr_of_games: 1}); |
||||
assert_eq!(*games[1], Game {id: 1, p1: (String::from("Alice"), 0), p2: (String::from("Mark"), 0), nbr_of_games: 3}); |
||||
assert_eq!(*games[2], Game {id: 2, p1: (String::from("Jack"), 0), p2: (String::from("Miller"), 0), nbr_of_games: 5}); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_update_and_read() { |
||||
let mut games = create_games(); |
||||
games[0].update_score(String::from("player1")); |
||||
assert_eq!(games[0].read_winner(), (String::from("player1"), 1)); |
||||
|
||||
games[0].update_score(String::from("player2")); |
||||
// this will stay the same because the nbr_of_games is 1 so if one
|
||||
// of the players wins just once it will no longer increment the score
|
||||
assert_eq!(games[0].read_winner(), (String::from("player1"), 1)); |
||||
|
||||
games[2].update_score(String::from("Jack")); |
||||
games[2].update_score(String::from("Jack")); |
||||
games[2].update_score(String::from("Miller")); |
||||
games[2].update_score(String::from("Miller")); |
||||
// tie between players
|
||||
assert_eq!(games[2].read_winner(), (String::from("Same score! tied"), 2)); |
||||
|
||||
games[2].update_score(String::from("Jack")); |
||||
assert_eq!(games[2].read_winner(), (String::from("Jack"), 3)); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_delete() { |
||||
let game = Game::new(0, String::from("Alice"), String::from("Mark"), 3); |
||||
let game1 = Game::new(23, String::from("Jack"), String::from("Miller"), 1); |
||||
|
||||
assert_eq!(game.delete(), String::from("game deleted: id -> 0")); |
||||
assert_eq!(game1.delete(), String::from("game deleted: id -> 23")); |
||||
} |
||||
|
||||
// #[test]
|
||||
// #[should_panic]
|
||||
// fn test_delete_ownership() {
|
||||
// let game = new(0, String::from("Alice"), String::from("Mark"), 3);
|
||||
// {
|
||||
// let a = &game;
|
||||
// // error! cant destroy boxed while the inner value is borrowed later in scope
|
||||
// delete(game);
|
||||
// read_winner(&a);
|
||||
// }
|
||||
// }
|
||||
} |
@ -1,38 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "borrow_me_the_reference" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"meval", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "borrow_me_the_reference_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"borrow_me_the_reference", |
||||
"meval", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "fnv" |
||||
version = "1.0.7" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" |
||||
|
||||
[[package]] |
||||
name = "meval" |
||||
version = "0.2.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "f79496a5651c8d57cd033c5add8ca7ee4e3d5f7587a4777484640d9cb60392d9" |
||||
dependencies = [ |
||||
"fnv", |
||||
"nom", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "nom" |
||||
version = "1.2.4" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce" |
@ -1,11 +0,0 @@
|
||||
[package] |
||||
name = "borrow_me_the_reference_test" |
||||
version = "0.1.0" |
||||
authors = ["lee <lee-dasilva@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
meval = "0.2" |
||||
borrow_me_the_reference = { path = "../../../../rust-piscine-solutions/borrow_me_the_reference"} |
@ -1,127 +0,0 @@
|
||||
/* |
||||
## borrowing_or_not_to_borrow |
||||
|
||||
### Instructions |
||||
|
||||
Ownership is Rust's most unique feature, and it enables Rust to make memory safety guarantees without |
||||
needing garbage collector. Therefore you must understand ownership in rust. |
||||
|
||||
Create the following functions : |
||||
|
||||
- `delete_and_backspace`, imagine that `-` represents the backspace key and the `+` represents the |
||||
delete key, this function must receive a borrowed string and turn this string into the string without |
||||
the backspaces and the deletes. Example: `delete_and_backspace("bpp--o+erroi-+cw") // output: "borrow"`
|
||||
- `is_correct` that borrows a Vector of string literals with some correct and incorrect math equations |
||||
and replaces the correct equations with `✔` and the wrong with `✘` and returns a `usize` with the percentage |
||||
of correct equations. |
||||
|
||||
|
||||
### Example |
||||
|
||||
```rust |
||||
fn main() { |
||||
let mut a = String::from("bpp--o+er+++sskroi-++lcw"); |
||||
let mut b: Vec<&str> = vec!["2+2=4", "3+2=5", "10-3=3", "5+5=10"]; |
||||
|
||||
// - If a value does **not implement Copy**, it must be **borrowed** and so will be passed by **reference**.
|
||||
delete_and_backspace(&mut a); // the reference of the value
|
||||
let per = is_correct(&mut b); // the reference of the value
|
||||
|
||||
println!("{:?}", (a, b, per)); |
||||
// output: ("borrow", ["✔", "✔", "✘", "✔"], 75)
|
||||
} |
||||
``` |
||||
|
||||
### Notions |
||||
|
||||
- https://doc.rust-lang.org/book/ch04-00-understanding-ownership.html
|
||||
- https://docs.rs/meval/0.2.0/meval/
|
||||
|
||||
*/ |
||||
use borrow_me_the_reference::*; |
||||
//use meval::eval_str;
|
||||
|
||||
// fn d_a_b(s: String) -> String {
|
||||
// let mut new_string = String::new();
|
||||
// let mut count = 0;
|
||||
// for v in s.chars() {
|
||||
// if count != 0 && v != '+' {
|
||||
// count -= 1;
|
||||
// continue;
|
||||
// }
|
||||
// if v == '+' {
|
||||
// count += 1;
|
||||
// continue;
|
||||
// }
|
||||
// new_string.push(v);
|
||||
// if v == '-' {
|
||||
// new_string.pop();
|
||||
// new_string.pop();
|
||||
// }
|
||||
// }
|
||||
// new_string
|
||||
// }
|
||||
// - If a value does **not implement Copy**, it must be **borrowed** and so will be passed by **reference**.
|
||||
// this is not good in rust because strings are not to be manipulated like this
|
||||
// but its a good view for the students to see how memory works in rust
|
||||
// fn delete_and_backspace(s: &mut String) {
|
||||
// let a = d_a_b(s.clone());
|
||||
// s.clear();
|
||||
// s.push_str(&a);
|
||||
// }
|
||||
|
||||
// - If a value does **not implement Copy**, it must be **borrowed** and so will be passed by **reference**.
|
||||
// fn is_correct(v: &mut Vec<&str>) -> usize {
|
||||
// let mut percentage = 0;
|
||||
// for (i, equation) in v.clone().iter().enumerate() {
|
||||
// let a: Vec<&str> = equation.split('=').collect();
|
||||
// if eval_str(a[0]).unwrap() == a[1].parse::<f64>().unwrap() {
|
||||
// v[i] = "✔";
|
||||
// percentage += 1;
|
||||
// } else {
|
||||
// v[i] = "✘";
|
||||
// }
|
||||
// }
|
||||
// (percentage * 100) / v.len()
|
||||
// }
|
||||
|
||||
#[test] |
||||
fn reference_string() { |
||||
let mut a_1 = String::from("bpp--o+er+++sskroi-++lcw"); |
||||
let mut a_2 = String::from("hs-+deasdasd------l+++dsdp"); |
||||
let mut a_3 = String::from("pad-rtic+eulqw--+rar"); |
||||
delete_and_backspace(&mut a_1); |
||||
delete_and_backspace(&mut a_2); |
||||
delete_and_backspace(&mut a_3); |
||||
assert_eq!(a_1, "borrow".to_string()); |
||||
assert_eq!(a_2, "help".to_string()); |
||||
assert_eq!(a_3, "particular".to_string()); |
||||
} |
||||
#[test] |
||||
fn reference_vec() { |
||||
let mut b_1: Vec<&str> = vec!["2+2=4", "3+2=5", "10-3=3", "5+5=10"]; |
||||
let mut b_2: Vec<&str> = vec!["1+2=4", "0+2=5", "10-3=3", "41+5=10"]; |
||||
let mut b_3: Vec<&str> = vec!["2+2=4", "3+2=5", "10-3=7", "5+5=10"]; |
||||
let result_1 = is_correct(&mut b_1); |
||||
let result_2 = is_correct(&mut b_2); |
||||
let result_3 = is_correct(&mut b_3); |
||||
assert_eq!(result_1, 75); |
||||
assert_eq!(result_2, 0); |
||||
assert_eq!(result_3, 100); |
||||
|
||||
assert_eq!(b_1, vec!["✔", "✔", "✘", "✔"]); |
||||
assert_eq!(b_2, vec!["✘", "✘", "✘", "✘"]); |
||||
assert_eq!(b_3, vec!["✔", "✔", "✔", "✔"]); |
||||
} |
||||
|
||||
fn main() { |
||||
let mut a = String::from("bpp--o+er+++sskroi-++lcw"); |
||||
let mut b: Vec<&str> = vec!["2+2=4", "3+2=5", "10-3=3", "5+5=10"]; |
||||
|
||||
// - If a value does **not implement Copy**, it must be **borrowed** and so will be passed by **reference**.
|
||||
delete_and_backspace(&mut a); // the reference of the value
|
||||
let per = is_correct(&mut b); // the reference of the value
|
||||
|
||||
println!("{:?}", (a, b, per)); |
||||
// output: ("borrow", ["✔", "✔", "✘", "✔"], 75)
|
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "borrow" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "borrow_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"borrow", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "borrow_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
borrow = { path = "../../../../rust-piscine-solutions/borrow"} |
@ -1,85 +0,0 @@
|
||||
/* |
||||
## borrow |
||||
|
||||
### Instructions |
||||
|
||||
Complete the signature and the body of the `str_len` function so it |
||||
receives a string or a string literal and returns its length (of type usize) |
||||
without taking ownership of the value (i.e, borrowing the value) |
||||
|
||||
### Example |
||||
|
||||
```rust |
||||
fn main() { |
||||
let s = "hello"; |
||||
let s1 = "camelCase".to_string(); |
||||
|
||||
println!("\tstr_len(\"{}\") = {}", s, str_len(s)); |
||||
println!("\tstr_len(\"{}\") = {}", s1, str_len(&s1)); |
||||
} |
||||
``` |
||||
*/ |
||||
|
||||
use borrow::*; |
||||
|
||||
fn main() { |
||||
let s = "hello"; |
||||
let s1 = "camelCase".to_string(); |
||||
|
||||
println!("\tstr_len(\"{}\") = {}", s, str_len(s)); |
||||
println!("\tstr_len(\"{}\") = {}", s1, str_len(&s1)); |
||||
} |
||||
|
||||
#[test] |
||||
// maybe not the best way to make the test, but I wanted to use
|
||||
// lifetimes
|
||||
fn str_len_test() { |
||||
struct TstLit<'a> { |
||||
str: &'a str, |
||||
l: usize, |
||||
} |
||||
|
||||
struct TstString { |
||||
str: String, |
||||
l: usize, |
||||
} |
||||
|
||||
let tsts = vec![ |
||||
TstLit { str: "hello", l: 5 }, |
||||
TstLit { str: "how", l: 3 }, |
||||
TstLit { |
||||
str: "are you", |
||||
l: 7, |
||||
}, |
||||
TstLit { |
||||
str: "change", |
||||
l: 6, |
||||
}, |
||||
]; |
||||
let o_tsts = vec![ |
||||
TstString { |
||||
str: "hello".to_string(), |
||||
l: 5, |
||||
}, |
||||
TstString { |
||||
str: "how".to_string(), |
||||
l: 3, |
||||
}, |
||||
TstString { |
||||
str: "are you".to_string(), |
||||
l: 7, |
||||
}, |
||||
TstString { |
||||
str: "change".to_string(), |
||||
l: 6, |
||||
}, |
||||
]; |
||||
|
||||
for t in tsts.iter() { |
||||
assert_eq!(t.l, str_len(t.str)); |
||||
} |
||||
|
||||
for t in o_tsts.iter() { |
||||
assert_eq!(t.l, str_len(&t.str)); |
||||
} |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "box_it" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "box_it_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"box_it", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "box_it_test" |
||||
version = "0.1.0" |
||||
authors = ["lee <lee-dasilva@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
box_it = { path = "../../../../rust-piscine-solutions/box_it"} |
@ -1,56 +0,0 @@
|
||||
use box_it::*; |
||||
|
||||
fn main() { |
||||
let new_str = String::from("5.5k 8.9k 32"); |
||||
|
||||
// creating a variable and we save it in the Heap
|
||||
let a_h = transform_and_save_on_heap(new_str); |
||||
println!("Box value : {:?}", &a_h); |
||||
println!("size occupied in the stack : {:?} bytes", (std::mem::size_of_val(&a_h))); |
||||
|
||||
let a_b_v = take_value_ownership(a_h); |
||||
println!("value : {:?}", &a_b_v); |
||||
println!("size occupied in the stack : {:?} bytes", (std::mem::size_of_val(&a_b_v))); |
||||
// whenever the box, in this case "a_h", goes out of scope it will be deallocated, freed
|
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
use std::mem; |
||||
|
||||
#[test] |
||||
fn test_transform() { |
||||
let new_str = String::from("5.5k 8.9k 32"); |
||||
let new_str_1 = String::from("6.8k 13.5k"); |
||||
let new_str_2 = String::from("20.3k 3.8k 7.7k 992"); |
||||
|
||||
let a = transform_and_save_on_heap(new_str); |
||||
let b = transform_and_save_on_heap(new_str_1); |
||||
let c = transform_and_save_on_heap(new_str_2); |
||||
|
||||
assert_eq!(a, Box::new(vec![5500, 8900, 32])); |
||||
assert_eq!(b, Box::new(vec![6800, 13500])); |
||||
assert_eq!(c, Box::new(vec![20300, 3800, 7700, 992])); |
||||
assert_eq!(mem::size_of_val(&a), 8); |
||||
assert_eq!(mem::size_of_val(&b), 8); |
||||
assert_eq!(mem::size_of_val(&c), 8); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_take_value_from_box() { |
||||
let new_str = String::from("5.5k 8.9k 32"); |
||||
let new_str_1 = String::from("6.8k 13.5k"); |
||||
let new_str_2 = String::from("20.3k 3.8k 7.7k 992"); |
||||
let a = take_value_ownership(transform_and_save_on_heap(new_str)); |
||||
let b = take_value_ownership(transform_and_save_on_heap(new_str_1)); |
||||
let c = take_value_ownership(transform_and_save_on_heap(new_str_2)); |
||||
|
||||
assert_eq!(a, vec![5500, 8900, 32]); |
||||
assert_eq!(b, vec![6800, 13500]); |
||||
assert_eq!(c, vec![20300, 3800, 7700, 992]); |
||||
assert_eq!(mem::size_of_val(&a), 24); |
||||
assert_eq!(mem::size_of_val(&b), 24); |
||||
assert_eq!(mem::size_of_val(&c), 24); |
||||
} |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "box_recursion" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "box_recursion_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"box_recursion", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "box_recursion_test" |
||||
version = "0.1.0" |
||||
authors = ["lee <lee-dasilva@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
box_recursion = { path = "../../../../rust-piscine-solutions/box_recursion"} |
@ -1,98 +0,0 @@
|
||||
use box_recursion::*; |
||||
|
||||
fn main() { |
||||
let mut list = WorkEnvironment::new(); |
||||
list.add_worker(String::from("CEO"), String::from("Marie")); |
||||
list.add_worker(String::from("Manager"), String::from("Monica")); |
||||
list.add_worker(String::from("Normal Worker"), String::from("Ana")); |
||||
list.add_worker(String::from("Normal Worker"), String::from("Alice")); |
||||
println!("{:?}", list); |
||||
|
||||
println!("{:?}", list.search_worker()); |
||||
|
||||
list.remove_worker(); |
||||
list.remove_worker(); |
||||
list.remove_worker(); |
||||
list.remove_worker(); |
||||
println!("{:?}", list); |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
|
||||
#[test] |
||||
fn test_new() { |
||||
let list = WorkEnvironment::new(); |
||||
assert!(list.grade.is_none()); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_one_worker() { |
||||
let mut list = WorkEnvironment::new(); |
||||
list.add_worker(String::from("CEO"), String::from("Marie")); |
||||
list.remove_worker(); |
||||
assert!(list.grade.is_none()); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_two_workers() { |
||||
let mut list = WorkEnvironment::new(); |
||||
list.add_worker(String::from("CEO"), String::from("Marie")); |
||||
list.add_worker(String::from("Manager"), String::from("Monica")); |
||||
list.remove_worker(); |
||||
|
||||
assert_eq!(list.grade.as_ref().unwrap().worker_type, "CEO"); |
||||
assert_eq!(list.grade.as_ref().unwrap().worker_name, "Marie"); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_more_workers() { |
||||
let mut list = WorkEnvironment::new(); |
||||
list.add_worker(String::from("CEO"), String::from("Marie")); |
||||
list.add_worker(String::from("Manager"), String::from("Monica")); |
||||
list.add_worker(String::from("Normal Worker"), String::from("Ana")); |
||||
list.add_worker(String::from("Normal Worker"), String::from("Alice")); |
||||
list.remove_worker(); |
||||
|
||||
assert_eq!(list.grade.as_ref().unwrap().worker_type, "Normal Worker"); |
||||
assert_eq!(list.grade.as_ref().unwrap().worker_name, "Ana"); |
||||
|
||||
list.remove_worker(); |
||||
list.remove_worker(); |
||||
assert_eq!(list.grade.as_ref().unwrap().worker_type, "CEO"); |
||||
assert_eq!(list.grade.as_ref().unwrap().worker_name, "Marie"); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_search() { |
||||
let mut list = WorkEnvironment::new(); |
||||
list.add_worker(String::from("CEO"), String::from("Marie")); |
||||
list.add_worker(String::from("Manager"), String::from("Monica")); |
||||
list.add_worker(String::from("Normal Worker"), String::from("Ana")); |
||||
list.add_worker(String::from("Normal Worker"), String::from("Alice")); |
||||
|
||||
assert_eq!( |
||||
list.search_worker().unwrap(), |
||||
(String::from("Alice"), String::from("Normal Worker")) |
||||
); |
||||
|
||||
list.remove_worker(); |
||||
assert_eq!( |
||||
list.search_worker().unwrap(), |
||||
(String::from("Ana"), String::from("Normal Worker")) |
||||
); |
||||
|
||||
list.remove_worker(); |
||||
assert_eq!( |
||||
list.search_worker().unwrap(), |
||||
(String::from("Monica"), String::from("Manager")) |
||||
); |
||||
|
||||
list.remove_worker(); |
||||
assert_eq!( |
||||
list.search_worker().unwrap(), |
||||
(String::from("Marie"), String::from("CEO")) |
||||
); |
||||
} |
||||
} |
@ -1,96 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "boxing_todo" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"serde", |
||||
"serde_json", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "boxing_todo_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"boxing_todo", |
||||
"serde", |
||||
"serde_json", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "itoa" |
||||
version = "0.4.7" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" |
||||
|
||||
[[package]] |
||||
name = "proc-macro2" |
||||
version = "1.0.24" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" |
||||
dependencies = [ |
||||
"unicode-xid", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "quote" |
||||
version = "1.0.8" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df" |
||||
dependencies = [ |
||||
"proc-macro2", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "ryu" |
||||
version = "1.0.5" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" |
||||
|
||||
[[package]] |
||||
name = "serde" |
||||
version = "1.0.118" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800" |
||||
dependencies = [ |
||||
"serde_derive", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "serde_derive" |
||||
version = "1.0.118" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df" |
||||
dependencies = [ |
||||
"proc-macro2", |
||||
"quote", |
||||
"syn", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "serde_json" |
||||
version = "1.0.60" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "1500e84d27fe482ed1dc791a56eddc2f230046a040fa908c08bda1d9fb615779" |
||||
dependencies = [ |
||||
"itoa", |
||||
"ryu", |
||||
"serde", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "syn" |
||||
version = "1.0.56" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "a9802ddde94170d186eeee5005b798d9c159fa970403f1be19976d0cfb939b72" |
||||
dependencies = [ |
||||
"proc-macro2", |
||||
"quote", |
||||
"unicode-xid", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "unicode-xid" |
||||
version = "0.2.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" |
@ -1,12 +0,0 @@
|
||||
[package] |
||||
name = "boxing_todo_test" |
||||
version = "0.1.0" |
||||
authors = ["lee <lee-dasilva@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
boxing_todo = { path = "../../../../rust-piscine-solutions/boxing_todo"} |
||||
serde = { version = "1.0", features = ["derive"] } |
||||
serde_json = "1.0" |
@ -1,99 +0,0 @@
|
||||
use boxing_todo::*; |
||||
|
||||
// Note that you can create some todo list your self to test it, but you can find the JSON files that
|
||||
// are being tested [here](https://github.com/01-edu/public/blob/master/subjects/boxing_todo)
|
||||
fn main() { |
||||
let todos = TodoList::get_todo("todo.json"); |
||||
match todos { |
||||
Ok(list) => println!("{:?}", list), |
||||
Err(e) => { |
||||
println!("{}{:?}", e.description(), e.cause()); |
||||
} |
||||
} |
||||
|
||||
let todos = TodoList::get_todo("malforned_object.json"); |
||||
match todos { |
||||
Ok(list) => println!("{:?}", list), |
||||
Err(e) => { |
||||
println!("{}{:?}", e.description(), e.cause().unwrap()); |
||||
} |
||||
} |
||||
|
||||
let todos = TodoList::get_todo("permission_err.json"); |
||||
match todos { |
||||
Ok(list) => println!("{:?}", list), |
||||
Err(e) => { |
||||
println!("{}{:?}", e.description(), e.cause().unwrap()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
use std::fs::File; |
||||
use std::fs; |
||||
|
||||
fn new_todo(s: String, v: Vec<Task>) -> TodoList { |
||||
TodoList { title: s, tasks: v } |
||||
} |
||||
fn run(s: &TodoList, f: &str) -> Result<TodoList, Box<dyn Error>> { |
||||
serde_json::to_writer(&File::create(f)?, s)?; |
||||
let result = TodoList::get_todo(f); |
||||
fs::remove_file(f)?; |
||||
return result; |
||||
} |
||||
|
||||
#[test] |
||||
fn test_good_todo() { |
||||
let file_name = "todo.json"; |
||||
let good_struct = new_todo( |
||||
String::from("todo list for something"), |
||||
vec![ |
||||
Task { id: 0, description: "do this".to_string(), level: 0 }, |
||||
Task { id: 1, description: "do that".to_string(), level: 5 }, |
||||
], |
||||
); |
||||
let result = run(&good_struct, file_name).unwrap(); |
||||
|
||||
assert_eq!(result.title, good_struct.title); |
||||
assert_eq!(&result.tasks, &good_struct.tasks); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_empty_tasks() { |
||||
let file_name = "empty_tasks.json"; |
||||
let result = run(&new_todo(String::from("empty tasks"), vec![]), file_name).unwrap_err(); |
||||
|
||||
assert_eq!(result.to_string(), "Failed to parses todo"); |
||||
assert_eq!(result.description(), "Todo List parse failed: "); |
||||
assert!(!result.cause().is_some()); |
||||
} |
||||
#[test] |
||||
fn test_read() { |
||||
let result = TodoList::get_todo("no_file.json").unwrap_err(); |
||||
|
||||
assert_eq!(result.to_string(), "Failed to read todo file"); |
||||
assert_eq!(result.description(), "Todo List read failed: "); |
||||
} |
||||
|
||||
#[test] |
||||
#[should_panic(expected = "Malformed(Error(\"missing field `title`\", line: 1, column: 2))")] |
||||
fn test_malformed_json() { |
||||
#[derive(Serialize, Deserialize)] |
||||
struct Mal {}; |
||||
let file_name = "malformed.json"; |
||||
let malformed: Mal = serde_json::from_str(r#"{}"#).unwrap(); |
||||
serde_json::to_writer(&File::create(file_name).unwrap(), &malformed).unwrap(); |
||||
let result = TodoList::get_todo(file_name); |
||||
fs::remove_file(file_name).unwrap(); |
||||
|
||||
result.unwrap_or_else(|e| panic!("{:?}", e)); |
||||
} |
||||
|
||||
#[test] |
||||
#[should_panic(expected = "ReadErr { child_err: Os { code: 2, kind: NotFound, message: \"No such file or directory\" } }")] |
||||
fn test_read_error() { |
||||
TodoList::get_todo("no_file.json").unwrap_or_else(|e| panic!("{:?}", e)); |
||||
} |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "capitalizing" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "capitalizing_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"capitalizing", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "capitalizing_test" |
||||
version = "0.1.0" |
||||
authors = ["MSilva95 <miguel-silva98@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
capitalizing = { path = "../../../../rust-piscine-solutions/capitalizing"} |
@ -1,38 +0,0 @@
|
||||
// Complete the `capitalize_first` function that turns the first letter of a string uppercase.
|
||||
// Complete the `title_case` function that turns the first letter of each word in a string uppercase.
|
||||
// Complete the `change_case` function that turns the uppercase letters of a string into lowercase and
|
||||
// the lowercase letters into uppercase.
|
||||
|
||||
use capitalizing::*; |
||||
|
||||
#[allow(dead_code)] |
||||
fn main() { |
||||
println!("{}", capitalize_first("joe is missing")); |
||||
println!("{}", title_case("jill is leaving A")); |
||||
println!("{}", change_case("heLLo THere")); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_success() { |
||||
assert_eq!(capitalize_first("hello"), "Hello"); |
||||
assert_eq!(capitalize_first("this is working"), "This is working"); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_titlle_case() { |
||||
assert_eq!(title_case("this is a tittle"), "This Is A Tittle"); |
||||
assert_eq!(title_case("hello my name is carl"), "Hello My Name Is Carl"); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_change_case() { |
||||
assert_eq!(change_case("PROgraming"), "proGRAMING"); |
||||
assert_eq!(change_case("heLLo THere"), "HEllO thERE"); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_empty() { |
||||
assert_eq!(capitalize_first(""), ""); |
||||
assert_eq!(title_case(""), ""); |
||||
assert_eq!(change_case(""), ""); |
||||
} |
@ -1,96 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "card_deck" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"rand 0.3.23", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "card_deck_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"card_deck", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "fuchsia-cprng" |
||||
version = "0.1.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" |
||||
|
||||
[[package]] |
||||
name = "libc" |
||||
version = "0.2.71" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" |
||||
|
||||
[[package]] |
||||
name = "rand" |
||||
version = "0.3.23" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" |
||||
dependencies = [ |
||||
"libc", |
||||
"rand 0.4.6", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand" |
||||
version = "0.4.6" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" |
||||
dependencies = [ |
||||
"fuchsia-cprng", |
||||
"libc", |
||||
"rand_core 0.3.1", |
||||
"rdrand", |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand_core" |
||||
version = "0.3.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" |
||||
dependencies = [ |
||||
"rand_core 0.4.2", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand_core" |
||||
version = "0.4.2" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" |
||||
|
||||
[[package]] |
||||
name = "rdrand" |
||||
version = "0.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" |
||||
dependencies = [ |
||||
"rand_core 0.3.1", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "winapi" |
||||
version = "0.3.8" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" |
||||
dependencies = [ |
||||
"winapi-i686-pc-windows-gnu", |
||||
"winapi-x86_64-pc-windows-gnu", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "winapi-i686-pc-windows-gnu" |
||||
version = "0.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" |
||||
|
||||
[[package]] |
||||
name = "winapi-x86_64-pc-windows-gnu" |
||||
version = "0.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "card_deck_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
card_deck = { path = "../../../../rust-piscine-solutions/card_deck"} |
@ -1,40 +0,0 @@
|
||||
// Create a enum that represent the card suits
|
||||
use card_deck::{self, Card, Rank, Suit}; |
||||
|
||||
// Write a program that takes that returns a random card in the deck
|
||||
// A standard deck of cards has 52 cards: 4 suits and 13 cards per suit
|
||||
#[allow(dead_code)] |
||||
fn main() { |
||||
let your_card = Card { |
||||
rank: Rank::random(), |
||||
suit: Suit::random(), |
||||
}; |
||||
|
||||
println!("You're card is {:?}", your_card); |
||||
|
||||
// Now if the card is an Ace of Spades print "You are the winner"
|
||||
if card_deck::winner_card(your_card) { |
||||
println!("You are the winner!"); |
||||
} |
||||
} |
||||
|
||||
#[test] |
||||
fn test_winner() { |
||||
let winner = Card { |
||||
rank: Rank::Ace, |
||||
suit: Suit::Spade, |
||||
}; |
||||
for rank in 1..14 { |
||||
for suit in 1..5 { |
||||
let card = Card { |
||||
rank: Rank::traslate(rank), |
||||
suit: Suit::translate(suit), |
||||
}; |
||||
if card != winner { |
||||
assert!(!card_deck::winner_card(card)); |
||||
} else { |
||||
assert!(card_deck::winner_card(card)); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,87 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "assert_cmd" |
||||
version = "1.0.2" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "3dc1679af9a1ab4bea16f228b05d18f8363f8327b1fa8db00d2760cfafc6b61e" |
||||
dependencies = [ |
||||
"doc-comment", |
||||
"predicates", |
||||
"predicates-core", |
||||
"predicates-tree", |
||||
"wait-timeout", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "changes" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"assert_cmd", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "changes_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"changes", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "difference" |
||||
version = "2.0.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" |
||||
|
||||
[[package]] |
||||
name = "doc-comment" |
||||
version = "0.3.3" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" |
||||
|
||||
[[package]] |
||||
name = "libc" |
||||
version = "0.2.81" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" |
||||
|
||||
[[package]] |
||||
name = "predicates" |
||||
version = "1.0.6" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "73dd9b7b200044694dfede9edf907c1ca19630908443e9447e624993700c6932" |
||||
dependencies = [ |
||||
"difference", |
||||
"predicates-core", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "predicates-core" |
||||
version = "1.0.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "fb3dbeaaf793584e29c58c7e3a82bbb3c7c06b63cea68d13b0e3cddc124104dc" |
||||
|
||||
[[package]] |
||||
name = "predicates-tree" |
||||
version = "1.0.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "aee95d988ee893cb35c06b148c80ed2cd52c8eea927f50ba7a0be1a786aeab73" |
||||
dependencies = [ |
||||
"predicates-core", |
||||
"treeline", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "treeline" |
||||
version = "0.1.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" |
||||
|
||||
[[package]] |
||||
name = "wait-timeout" |
||||
version = "0.2.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" |
||||
dependencies = [ |
||||
"libc", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "changes_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
changes = { path = "../../../../rust-piscine-solutions/changes"} |
@ -1,54 +0,0 @@
|
||||
/* |
||||
## changes |
||||
|
||||
### Instructions |
||||
|
||||
Imagine you are working in a software to control smart lights in a |
||||
house. You have access to an array of all the lights in a house. |
||||
|
||||
Define the associated function `new` to the data structure `Light` |
||||
which creates a new light with the alias passed in the arguments and |
||||
a brightness of 0. |
||||
|
||||
Define the function `change_brightness` that receives a Vec of lights, |
||||
an alias and a u8 value and sets the u8 value as the new brightness of the light |
||||
identified by the alias in the Vec of lights. |
||||
*/ |
||||
|
||||
use changes::*; |
||||
|
||||
fn main() { |
||||
// bedroom
|
||||
let mut lights = vec![ |
||||
Light::new("living_room"), |
||||
Light::new("bedroom"), |
||||
Light::new("rest_room"), |
||||
]; |
||||
println!("brightness = {}", lights[0].brightness); |
||||
change_brightness(&mut lights, "living_room", 200); |
||||
println!("new brightness = {}", lights[0].brightness); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_unexistente_alias() { |
||||
let mut lights = Vec::new(); |
||||
for i in 0..5 { |
||||
let alias = format!("light-{}", i); |
||||
lights.push(Light::new(&alias)); |
||||
} |
||||
let copy = lights.clone(); |
||||
change_brightness(&mut lights, "light-6", 100); |
||||
assert_eq!(copy, lights); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_alias() { |
||||
let mut lights = Vec::new(); |
||||
for i in 0..5 { |
||||
let alias = format!("light-{}", i); |
||||
lights.push(Light::new(&alias)); |
||||
} |
||||
let alias = "light-3"; |
||||
change_brightness(&mut lights, alias, 100); |
||||
assert_eq!(lights[3].brightness, 100); |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "cipher" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "cipher_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"cipher", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "cipher_test" |
||||
version = "0.1.0" |
||||
authors = ["lee <lee-dasilva@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
cipher = { path = "../../../../rust-piscine-solutions/cipher"} |
@ -1,24 +0,0 @@
|
||||
use cipher::*; |
||||
|
||||
fn main() { |
||||
println!("{:?}", cipher("1Hello 2world!", "1Svool 2dliow!")); |
||||
println!("{:?}", cipher("1Hello 2world!", "svool")); |
||||
println!("{:?}", cipher("", "svool")); |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
|
||||
#[test] |
||||
fn test_cipher() { |
||||
assert_eq!(cipher("1Hello 2world!", "1Svool 2dliow!"), Some(Ok(true))); |
||||
assert_eq!(cipher("", "1Svool 2dliow!"), None); |
||||
assert_eq!(cipher("1Hello 2world!", ""), None); |
||||
assert_eq!(cipher("1Hello 2world!", "1svool 2dliow!"), Some(Err(CipherError { validation: false, expected: String::from("1Svool 2dliow!") }))); |
||||
assert_eq!(cipher("asdasd", "zhwzhw"), Some(Ok(true))); |
||||
assert_eq!(cipher("asdasd", "lkdas"), Some(Err(CipherError { validation: false, expected: String::from("zhwzhw") }))); |
||||
assert_eq!(cipher("3(/&%fsd 32das", "3(/&%uhw 32wzh"), Some(Ok(true))); |
||||
assert_eq!(cipher("3(/&%sd 32das", "3(/&%uhw 32wzh"), Some(Err(CipherError { validation: false, expected: String::from("3(/&%hw 32wzh") }))); |
||||
} |
||||
} |
@ -1,426 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "autocfg" |
||||
version = "1.0.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" |
||||
|
||||
[[package]] |
||||
name = "bitflags" |
||||
version = "0.7.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" |
||||
|
||||
[[package]] |
||||
name = "byteorder" |
||||
version = "0.5.3" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" |
||||
|
||||
[[package]] |
||||
name = "byteorder" |
||||
version = "1.3.4" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" |
||||
|
||||
[[package]] |
||||
name = "cc" |
||||
version = "1.0.54" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "7bbb73db36c1246e9034e307d0fba23f9a2e251faa47ade70c1bd252220c8311" |
||||
|
||||
[[package]] |
||||
name = "cfg-if" |
||||
version = "0.1.10" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" |
||||
|
||||
[[package]] |
||||
name = "circle" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"raster", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "circle_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"circle", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "color_quant" |
||||
version = "1.0.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "0dbbb57365263e881e805dc77d94697c9118fd94d8da011240555aa7b23445bd" |
||||
|
||||
[[package]] |
||||
name = "crossbeam-deque" |
||||
version = "0.7.3" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" |
||||
dependencies = [ |
||||
"crossbeam-epoch", |
||||
"crossbeam-utils", |
||||
"maybe-uninit", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "crossbeam-epoch" |
||||
version = "0.8.2" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" |
||||
dependencies = [ |
||||
"autocfg", |
||||
"cfg-if", |
||||
"crossbeam-utils", |
||||
"lazy_static", |
||||
"maybe-uninit", |
||||
"memoffset", |
||||
"scopeguard", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "crossbeam-queue" |
||||
version = "0.2.3" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" |
||||
dependencies = [ |
||||
"cfg-if", |
||||
"crossbeam-utils", |
||||
"maybe-uninit", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "crossbeam-utils" |
||||
version = "0.7.2" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" |
||||
dependencies = [ |
||||
"autocfg", |
||||
"cfg-if", |
||||
"lazy_static", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "either" |
||||
version = "1.5.3" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" |
||||
|
||||
[[package]] |
||||
name = "enum_primitive" |
||||
version = "0.1.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "be4551092f4d519593039259a9ed8daedf0da12e5109c5280338073eaeb81180" |
||||
dependencies = [ |
||||
"num-traits 0.1.43", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "flate2" |
||||
version = "0.2.20" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "e6234dd4468ae5d1e2dbb06fe2b058696fdc50a339c68a393aefbf00bc81e423" |
||||
dependencies = [ |
||||
"libc", |
||||
"miniz-sys", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "fuchsia-cprng" |
||||
version = "0.1.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" |
||||
|
||||
[[package]] |
||||
name = "gif" |
||||
version = "0.9.2" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "e2e41945ba23db3bf51b24756d73d81acb4f28d85c3dccc32c6fae904438c25f" |
||||
dependencies = [ |
||||
"color_quant", |
||||
"lzw", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "glob" |
||||
version = "0.2.11" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" |
||||
|
||||
[[package]] |
||||
name = "hermit-abi" |
||||
version = "0.1.13" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "91780f809e750b0a89f5544be56617ff6b1227ee485bcb06ebe10cdf89bd3b71" |
||||
dependencies = [ |
||||
"libc", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "image" |
||||
version = "0.10.4" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "76df2dce95fef56fd35dbc41c36e37b19aede703c6be7739e8b65d5788ffc728" |
||||
dependencies = [ |
||||
"byteorder 0.5.3", |
||||
"enum_primitive", |
||||
"glob", |
||||
"jpeg-decoder", |
||||
"num-iter", |
||||
"num-rational", |
||||
"num-traits 0.1.43", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "inflate" |
||||
version = "0.1.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "e7e0062d2dc2f17d2f13750d95316ae8a2ff909af0fda957084f5defd87c43bb" |
||||
|
||||
[[package]] |
||||
name = "jpeg-decoder" |
||||
version = "0.1.19" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "5b47b4c4e017b01abdc5bcc126d2d1002e5a75bbe3ce73f9f4f311a916363704" |
||||
dependencies = [ |
||||
"byteorder 1.3.4", |
||||
"rayon", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "lazy_static" |
||||
version = "1.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" |
||||
|
||||
[[package]] |
||||
name = "libc" |
||||
version = "0.2.71" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" |
||||
|
||||
[[package]] |
||||
name = "lzw" |
||||
version = "0.10.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084" |
||||
|
||||
[[package]] |
||||
name = "maybe-uninit" |
||||
version = "2.0.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" |
||||
|
||||
[[package]] |
||||
name = "memoffset" |
||||
version = "0.5.4" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "b4fc2c02a7e374099d4ee95a193111f72d2110197fe200272371758f6c3643d8" |
||||
dependencies = [ |
||||
"autocfg", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "miniz-sys" |
||||
version = "0.1.12" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "1e9e3ae51cea1576ceba0dde3d484d30e6e5b86dee0b2d412fe3a16a15c98202" |
||||
dependencies = [ |
||||
"cc", |
||||
"libc", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "num-bigint" |
||||
version = "0.1.44" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "e63899ad0da84ce718c14936262a41cee2c79c981fc0a0e7c7beb47d5a07e8c1" |
||||
dependencies = [ |
||||
"num-integer", |
||||
"num-traits 0.2.12", |
||||
"rand", |
||||
"rustc-serialize", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "num-integer" |
||||
version = "0.1.43" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" |
||||
dependencies = [ |
||||
"autocfg", |
||||
"num-traits 0.2.12", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "num-iter" |
||||
version = "0.1.41" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "7a6e6b7c748f995c4c29c5f5ae0248536e04a5739927c74ec0fa564805094b9f" |
||||
dependencies = [ |
||||
"autocfg", |
||||
"num-integer", |
||||
"num-traits 0.2.12", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "num-rational" |
||||
version = "0.1.42" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "ee314c74bd753fc86b4780aa9475da469155f3848473a261d2d18e35245a784e" |
||||
dependencies = [ |
||||
"num-bigint", |
||||
"num-integer", |
||||
"num-traits 0.2.12", |
||||
"rustc-serialize", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "num-traits" |
||||
version = "0.1.43" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" |
||||
dependencies = [ |
||||
"num-traits 0.2.12", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "num-traits" |
||||
version = "0.2.12" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" |
||||
dependencies = [ |
||||
"autocfg", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "num_cpus" |
||||
version = "1.13.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" |
||||
dependencies = [ |
||||
"hermit-abi", |
||||
"libc", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "png" |
||||
version = "0.5.2" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "06208e2ee243e3118a55dda9318f821f206d8563fb8d4df258767f8e62bb0997" |
||||
dependencies = [ |
||||
"bitflags", |
||||
"flate2", |
||||
"inflate", |
||||
"num-iter", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand" |
||||
version = "0.4.6" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" |
||||
dependencies = [ |
||||
"fuchsia-cprng", |
||||
"libc", |
||||
"rand_core 0.3.1", |
||||
"rdrand", |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand_core" |
||||
version = "0.3.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" |
||||
dependencies = [ |
||||
"rand_core 0.4.2", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand_core" |
||||
version = "0.4.2" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" |
||||
|
||||
[[package]] |
||||
name = "raster" |
||||
version = "0.2.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "4c3f9e9cfa4260e25ea0d3bc72f3724afbeb65a61f8cb4d38c1d4de5309cd7ef" |
||||
dependencies = [ |
||||
"gif", |
||||
"image", |
||||
"png", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rayon" |
||||
version = "1.3.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "db6ce3297f9c85e16621bb8cca38a06779ffc31bb8184e1be4bed2be4678a098" |
||||
dependencies = [ |
||||
"crossbeam-deque", |
||||
"either", |
||||
"rayon-core", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rayon-core" |
||||
version = "1.7.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "08a89b46efaf957e52b18062fb2f4660f8b8a4dde1807ca002690868ef2c85a9" |
||||
dependencies = [ |
||||
"crossbeam-deque", |
||||
"crossbeam-queue", |
||||
"crossbeam-utils", |
||||
"lazy_static", |
||||
"num_cpus", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rdrand" |
||||
version = "0.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" |
||||
dependencies = [ |
||||
"rand_core 0.3.1", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rustc-serialize" |
||||
version = "0.3.24" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" |
||||
|
||||
[[package]] |
||||
name = "scopeguard" |
||||
version = "1.1.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" |
||||
|
||||
[[package]] |
||||
name = "winapi" |
||||
version = "0.3.8" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" |
||||
dependencies = [ |
||||
"winapi-i686-pc-windows-gnu", |
||||
"winapi-x86_64-pc-windows-gnu", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "winapi-i686-pc-windows-gnu" |
||||
version = "0.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" |
||||
|
||||
[[package]] |
||||
name = "winapi-x86_64-pc-windows-gnu" |
||||
version = "0.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "circle_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
circle = { path = "../../../../rust-piscine-solutions/circle"} |
@ -1,70 +0,0 @@
|
||||
//use raster::{Color, Image};
|
||||
use circle::{Circle, Point}; |
||||
// Create a structure that represents a circle
|
||||
// using the radius and the center point
|
||||
|
||||
fn main() { |
||||
let circle = Circle::new(500.0, 500.0, 150.0); |
||||
let circle1 = Circle { |
||||
center: Point { x: 80.0, y: 115.0 }, |
||||
radius: 30.0, |
||||
}; |
||||
let point_a = Point { x: 1.0, y: 1.0 }; |
||||
let point_b = Point { x: 0.0, y: 0.0 }; |
||||
println!("circle = {:?} area = {}", circle, circle.area()); |
||||
println!("circle = {:?} diameter = {}", circle, circle.diameter()); |
||||
println!("circle1 = {:?} diameter = {}", circle1, circle1.diameter()); |
||||
println!( |
||||
"circle and circle1 intersect = {}", |
||||
circle.intersect(&circle1) |
||||
); |
||||
|
||||
println!( |
||||
"distance between {:?} and {:?} is {}", |
||||
point_a, |
||||
point_b, |
||||
point_a.distance(&point_b) |
||||
); |
||||
} |
||||
|
||||
#[allow(dead_code)] |
||||
fn approx_eq(a: f64, b: f64) -> bool { |
||||
(a - b).abs() < f64::EPSILON |
||||
} |
||||
|
||||
#[test] |
||||
fn test_new_circle() { |
||||
let circle = Circle::new(500.0, 400.0, 150.0); |
||||
assert!(approx_eq(circle.radius, 150.0)); |
||||
assert!(approx_eq(circle.center.x, 500.0)); |
||||
assert!(approx_eq(circle.center.y, 400.0)); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_distance() { |
||||
let a = Point { x: 0.0, y: 1.0 }; |
||||
let b = Point { x: 0.0, y: 0.0 }; |
||||
assert!(approx_eq(a.distance(&b), 1.0)); |
||||
let a = Point { x: 1.0, y: 0.0 }; |
||||
let b = Point { x: 0.0, y: 0.0 }; |
||||
assert!(approx_eq(a.distance(&b), 1.0)); |
||||
let a = Point { x: 1.0, y: 1.0 }; |
||||
let b = Point { x: 0.0, y: 0.0 }; |
||||
assert!(approx_eq(a.distance(&b), f64::sqrt(2.0))); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_area() { |
||||
let circle = Circle::new(500.0, 400.0, 150.0); |
||||
assert!(approx_eq(circle.area(), 70685.83470577035)); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_intersection() { |
||||
let circle = Circle::new(500.0, 500.0, 150.0); |
||||
let circle1 = Circle::new(80.0, 115.0, 30.0); |
||||
assert!(!circle.intersect(&circle1)); |
||||
let circle = Circle::new(100.0, 300.0, 150.0); |
||||
let circle1 = Circle::new(80.0, 115.0, 100.0); |
||||
assert!(circle.intersect(&circle1)); |
||||
} |
@ -1,12 +0,0 @@
|
||||
# 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", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "closures_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
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"} |
@ -1,28 +0,0 @@
|
||||
// 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()); |
||||
} |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "collect" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "collect_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"collect", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "collect_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
collect = { path = "../../../../rust-piscine-solutions/collect"} |
@ -1,25 +0,0 @@
|
||||
// Implement the function bubble_sort which receives a vector Vec<i32>
|
||||
// and return the same vector but in increasing order using the bubble
|
||||
// sort algorithm
|
||||
|
||||
use collect::*; |
||||
|
||||
fn main() { |
||||
let ref mut v = vec![3, 2, 4, 5, 1, 7]; |
||||
let mut b = v.clone(); |
||||
bubble_sort(v); |
||||
println!("{:?}", v); |
||||
|
||||
b.sort(); |
||||
println!("{:?}", b); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_ordering() { |
||||
let ref mut v = vec![3, 2, 4, 5, 1, 7]; |
||||
let mut b = v.clone(); |
||||
|
||||
b.sort(); |
||||
bubble_sort(v); |
||||
assert_eq!(*v, b); |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "copy" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "copy_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"copy", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "copy_test" |
||||
version = "0.1.0" |
||||
authors = ["lee <lee-dasilva@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
copy = { path = "../../../../rust-piscine-solutions/copy"} |
@ -1,105 +0,0 @@
|
||||
/* |
||||
## copy |
||||
|
||||
### Instructions |
||||
|
||||
Your objective is to fix the program so that all functions work. |
||||
|
||||
- `nbr_function`, returns a tuple with the original value, the exponential and logarithm of that value |
||||
- `str_function`, returns a tuple with the original value and the exponential of that value as a string |
||||
- `vec_function`, returns a tuple with the original value and the logarithm of each value |
||||
|
||||
The objective is to now how ownership works with different types. |
||||
|
||||
### Example |
||||
|
||||
```rust |
||||
fn main() { |
||||
let a = String::from("1 2 4 5 6"); |
||||
let b = vec![1, 2, 4, 5]; |
||||
let c: u32 = 0; |
||||
|
||||
println!("{:?}", nbr_function(c)); |
||||
// output: (12, 162754.79141900392, 2.4849066497880004)
|
||||
println!("{:?}", vec_function(b)); |
||||
// output: ([1, 2, 4], [0.0, 0.6931471805599453, 1.3862943611198906])
|
||||
println!("{:?}", str_function(a)); |
||||
// output: ("1 2 4", "2.718281828459045 7.38905609893065 54.598150033144236")
|
||||
} |
||||
``` |
||||
|
||||
### Notions |
||||
|
||||
- https://doc.rust-lang.org/rust-by-example/scope/move.html
|
||||
*/ |
||||
|
||||
use copy::*; |
||||
|
||||
#[allow(dead_code)] |
||||
fn main() { |
||||
let a = String::from("1 2 4 5 6"); |
||||
let b = vec![1, 2, 4, 5]; |
||||
let c: u32 = 0; |
||||
|
||||
println!("{:?}", nbr_function(c)); |
||||
// output: (12, 162754.79141900392, 2.4849066497880004)
|
||||
println!("{:?}", vec_function(b)); |
||||
// output: ([1, 2, 4], [0.0, 0.6931471805599453, 1.3862943611198906])
|
||||
println!("{:?}", str_function(a)); |
||||
// output: ("1 2 4", "2.718281828459045 7.38905609893065 54.598150033144236")
|
||||
} |
||||
|
||||
#[test] |
||||
fn ownership_nbr_test() { |
||||
assert_eq!( |
||||
nbr_function(12), |
||||
(12, 162754.79141900392, 2.4849066497880004) |
||||
); |
||||
assert_eq!(nbr_function(1), (1, 2.718281828459045, 0.0)); |
||||
assert_eq!(nbr_function(0), (0, 1.0, std::f64::INFINITY)); |
||||
} |
||||
|
||||
#[test] |
||||
fn ownership_vec_test() { |
||||
assert_eq!( |
||||
vec_function(vec![1, 2, 4]), |
||||
( |
||||
vec![1, 2, 4], |
||||
vec![0.0, 0.6931471805599453, 1.3862943611198906] |
||||
) |
||||
); |
||||
assert_eq!( |
||||
vec_function(vec![0, 1]), |
||||
(vec![0, 1], vec![std::f64::INFINITY, 0.0]) |
||||
); |
||||
assert_eq!( |
||||
vec_function(vec![1, 2, 4, 5]), |
||||
( |
||||
vec![1, 2, 4, 5], |
||||
vec![ |
||||
0.0, |
||||
0.6931471805599453, |
||||
1.3862943611198906, |
||||
1.6094379124341003 |
||||
] |
||||
) |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
fn ownership_str_test() { |
||||
assert_eq!( |
||||
str_function(String::from("1 2 4")), |
||||
( |
||||
"1 2 4".to_string(), |
||||
"2.718281828459045 7.38905609893065 54.598150033144236".to_string() |
||||
) |
||||
); |
||||
assert_eq!( |
||||
str_function(String::from("1 0")), |
||||
(("1 0".to_string(), "2.718281828459045 1".to_string())) |
||||
); |
||||
assert_eq!(str_function( |
||||
String::from("1 2 4 5 6")), |
||||
(("1 2 4 5 6".to_string(), "2.718281828459045 7.38905609893065 54.598150033144236 148.4131591025766 403.4287934927351".to_string()))); |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "delete_prefix" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "delete_prefix_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"delete_prefix", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "delete_prefix_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
delete_prefix = { path = "../../../../rust-piscine-solutions/delete_prefix"} |
@ -1,32 +0,0 @@
|
||||
// Define the function `delete_prefix(prefix: &str, s: &str) -> Option<&str>`
|
||||
// That takes 2 slices of string and returns the string of slice s
|
||||
// with the `prefix` removed wrapped in Some
|
||||
// If `prefix ` is not contained in `s` return None
|
||||
|
||||
// Example:
|
||||
// delete_prefix("hello, ", "hello, world")? == "world"
|
||||
// delete_prefix("not", "win");
|
||||
|
||||
use delete_prefix::*; |
||||
|
||||
#[allow(dead_code)] |
||||
fn main() { |
||||
println!("{:?}", delete_prefix("ab", "abcdefghijklmnop")); |
||||
println!("{:?}", delete_prefix("x", "abcdefghijklmnop")); |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
|
||||
#[test] |
||||
fn test_delete_prefix() { |
||||
assert_eq!(delete_prefix("john", "john wick"), Some(" wick")); |
||||
|
||||
assert_eq!(delete_prefix("ab", "b"), None); |
||||
|
||||
assert_eq!(delete_prefix("aa", "ab"), None); |
||||
|
||||
assert_eq!(delete_prefix("á©", "á©ab"), Some("ab")); |
||||
} |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "diamond_creation" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "diamond_creation_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"diamond_creation", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "diamond_creation_test" |
||||
version = "0.1.0" |
||||
authors = ["MSilva95 <miguel-silva98@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
diamond_creation = { path = "../../../../rust-piscine-solutions/diamond_creation"} |
@ -1,149 +0,0 @@
|
||||
/* |
||||
## diamond_creation |
||||
|
||||
### Instructions |
||||
|
||||
Complete the function "get_diamond" that takes a letter as input, and outputs it in a diamond shape. |
||||
|
||||
Rules: |
||||
|
||||
The first and last row contain one 'A'. |
||||
The given letter has to be at the widest point. |
||||
All rows, except the first and last, have exactly two identical letters. |
||||
All rows have as many trailing spaces as leading spaces. (This might be 0). |
||||
The diamond is vertically and horizontally symmetric. |
||||
The diamond width equals the height. |
||||
The top half has the letters in ascending order. (abcd) |
||||
The bottom half has the letters in descending order. (dcba) |
||||
|
||||
### Example: |
||||
|
||||
In the following examples, spaces are indicated by "·" |
||||
|
||||
EX: letter 'A': |
||||
|
||||
A |
||||
|
||||
EX: letter 'B': |
||||
|
||||
.A. |
||||
B.B |
||||
.A. |
||||
|
||||
EX: letter 'C': |
||||
|
||||
··A·· |
||||
·B·B· |
||||
C···C |
||||
·B·B· |
||||
··A·· |
||||
|
||||
EX: letter 'E': |
||||
|
||||
····A···· |
||||
···B·B··· |
||||
··C···C·· |
||||
·D·····D· |
||||
E·······E |
||||
·D·····D· |
||||
··C···C·· |
||||
···B·B··· |
||||
····A···· |
||||
|
||||
*/ |
||||
use diamond_creation::*; |
||||
fn main() { |
||||
println!("{:?}", get_diamond('A')); |
||||
println!("{:?}", get_diamond('C')); |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod test { |
||||
use super::*; |
||||
|
||||
#[test] |
||||
fn test_a() { |
||||
assert_eq!(get_diamond('A'), vec!["A"]); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_b() { |
||||
assert_eq!(get_diamond('B'), vec![" A ", "B B", " A "]); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_c() { |
||||
assert_eq!( |
||||
get_diamond('C'), |
||||
vec![" A ", " B B ", "C C", " B B ", " A "] |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_d() { |
||||
assert_eq!( |
||||
get_diamond('D'), |
||||
vec![" A ", " B B ", " C C ", "D D", " C C ", " B B ", " A ",] |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_z() { |
||||
assert_eq!( |
||||
get_diamond('Z'), |
||||
vec![ |
||||
" A ", |
||||
" B B ", |
||||
" C C ", |
||||
" D D ", |
||||
" E E ", |
||||
" F F ", |
||||
" G G ", |
||||
" H H ", |
||||
" I I ", |
||||
" J J ", |
||||
" K K ", |
||||
" L L ", |
||||
" M M ", |
||||
" N N ", |
||||
" O O ", |
||||
" P P ", |
||||
" Q Q ", |
||||
" R R ", |
||||
" S S ", |
||||
" T T ", |
||||
" U U ", |
||||
" V V ", |
||||
" W W ", |
||||
" X X ", |
||||
" Y Y ", |
||||
"Z Z", |
||||
" Y Y ", |
||||
" X X ", |
||||
" W W ", |
||||
" V V ", |
||||
" U U ", |
||||
" T T ", |
||||
" S S ", |
||||
" R R ", |
||||
" Q Q ", |
||||
" P P ", |
||||
" O O ", |
||||
" N N ", |
||||
" M M ", |
||||
" L L ", |
||||
" K K ", |
||||
" J J ", |
||||
" I I ", |
||||
" H H ", |
||||
" G G ", |
||||
" F F ", |
||||
" E E ", |
||||
" D D ", |
||||
" C C ", |
||||
" B B ", |
||||
" A ", |
||||
] |
||||
); |
||||
} |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "division_and_remainder" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "division_and_reminder_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"division_and_remainder", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "division_and_remainder_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
division_and_remainder= { path = "../../../../rust-piscine-solutions/division_and_remainder" } |
@ -1,35 +0,0 @@
|
||||
use division_and_remainder::*; |
||||
|
||||
fn main() { |
||||
let x = 9; |
||||
let y = 4; |
||||
let (division, remainder) = divide(x, y); |
||||
println!( |
||||
"\t{}/{}: division = {}, remainder = {}", |
||||
x, y, division, remainder |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
#[should_panic] |
||||
fn divide_by_0() { |
||||
divide(40, 0); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_divide() { |
||||
let (div, rem) = divide(40, 3); |
||||
|
||||
assert_eq!(div, 13); |
||||
assert_eq!(rem, 1); |
||||
|
||||
let (div, rem) = divide(389, 39); |
||||
|
||||
assert_eq!(div, 9); |
||||
assert_eq!(rem, 38); |
||||
|
||||
let (div, rem) = divide(29, 332); |
||||
|
||||
assert_eq!(div, 0); |
||||
assert_eq!(rem, 29); |
||||
} |
@ -1,483 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "aho-corasick" |
||||
version = "0.7.15" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" |
||||
dependencies = [ |
||||
"memchr", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "assert_fs" |
||||
version = "1.0.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "04dabd011e19821a348abb0dec7b7fda959cd6b3477c474395b958b291942b0e" |
||||
dependencies = [ |
||||
"doc-comment", |
||||
"globwalk", |
||||
"predicates", |
||||
"predicates-core", |
||||
"predicates-tree", |
||||
"tempfile", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "autocfg" |
||||
version = "1.0.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" |
||||
|
||||
[[package]] |
||||
name = "bstr" |
||||
version = "0.2.14" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "473fc6b38233f9af7baa94fb5852dca389e3d95b8e21c8e3719301462c5d9faf" |
||||
dependencies = [ |
||||
"memchr", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "cfg-if" |
||||
version = "0.1.10" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" |
||||
|
||||
[[package]] |
||||
name = "cfg-if" |
||||
version = "1.0.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" |
||||
|
||||
[[package]] |
||||
name = "crossbeam-utils" |
||||
version = "0.8.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" |
||||
dependencies = [ |
||||
"autocfg", |
||||
"cfg-if 1.0.0", |
||||
"lazy_static", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "difference" |
||||
version = "2.0.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" |
||||
|
||||
[[package]] |
||||
name = "doc-comment" |
||||
version = "0.3.3" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" |
||||
|
||||
[[package]] |
||||
name = "doubtful" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"assert_fs", |
||||
"escargot", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "doubtful_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"doubtful", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "escargot" |
||||
version = "0.5.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "74cf96bec282dcdb07099f7e31d9fed323bca9435a09aba7b6d99b7617bca96d" |
||||
dependencies = [ |
||||
"lazy_static", |
||||
"log", |
||||
"serde", |
||||
"serde_json", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "float-cmp" |
||||
version = "0.8.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "e1267f4ac4f343772758f7b1bdcbe767c218bbab93bb432acbf5162bbf85a6c4" |
||||
dependencies = [ |
||||
"num-traits", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "fnv" |
||||
version = "1.0.7" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" |
||||
|
||||
[[package]] |
||||
name = "getrandom" |
||||
version = "0.1.15" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" |
||||
dependencies = [ |
||||
"cfg-if 0.1.10", |
||||
"libc", |
||||
"wasi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "globset" |
||||
version = "0.4.6" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "c152169ef1e421390738366d2f796655fec62621dabbd0fd476f905934061e4a" |
||||
dependencies = [ |
||||
"aho-corasick", |
||||
"bstr", |
||||
"fnv", |
||||
"log", |
||||
"regex", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "globwalk" |
||||
version = "0.7.3" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "d9db17aec586697a93219b19726b5b68307eba92898c34b170857343fe67c99d" |
||||
dependencies = [ |
||||
"ignore", |
||||
"walkdir", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "ignore" |
||||
version = "0.4.17" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "b287fb45c60bb826a0dc68ff08742b9d88a2fea13d6e0c286b3172065aaf878c" |
||||
dependencies = [ |
||||
"crossbeam-utils", |
||||
"globset", |
||||
"lazy_static", |
||||
"log", |
||||
"memchr", |
||||
"regex", |
||||
"same-file", |
||||
"thread_local", |
||||
"walkdir", |
||||
"winapi-util", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "itoa" |
||||
version = "0.4.6" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" |
||||
|
||||
[[package]] |
||||
name = "lazy_static" |
||||
version = "1.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" |
||||
|
||||
[[package]] |
||||
name = "libc" |
||||
version = "0.2.81" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" |
||||
|
||||
[[package]] |
||||
name = "log" |
||||
version = "0.4.11" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" |
||||
dependencies = [ |
||||
"cfg-if 0.1.10", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "memchr" |
||||
version = "2.3.4" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" |
||||
|
||||
[[package]] |
||||
name = "normalize-line-endings" |
||||
version = "0.3.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" |
||||
|
||||
[[package]] |
||||
name = "num-traits" |
||||
version = "0.2.14" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" |
||||
dependencies = [ |
||||
"autocfg", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "ppv-lite86" |
||||
version = "0.2.10" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" |
||||
|
||||
[[package]] |
||||
name = "predicates" |
||||
version = "1.0.5" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "96bfead12e90dccead362d62bb2c90a5f6fc4584963645bc7f71a735e0b0735a" |
||||
dependencies = [ |
||||
"difference", |
||||
"float-cmp", |
||||
"normalize-line-endings", |
||||
"predicates-core", |
||||
"regex", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "predicates-core" |
||||
version = "1.0.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "06075c3a3e92559ff8929e7a280684489ea27fe44805174c3ebd9328dcb37178" |
||||
|
||||
[[package]] |
||||
name = "predicates-tree" |
||||
version = "1.0.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "8e63c4859013b38a76eca2414c64911fba30def9e3202ac461a2d22831220124" |
||||
dependencies = [ |
||||
"predicates-core", |
||||
"treeline", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "proc-macro2" |
||||
version = "1.0.24" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" |
||||
dependencies = [ |
||||
"unicode-xid", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "quote" |
||||
version = "1.0.8" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df" |
||||
dependencies = [ |
||||
"proc-macro2", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand" |
||||
version = "0.7.3" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" |
||||
dependencies = [ |
||||
"getrandom", |
||||
"libc", |
||||
"rand_chacha", |
||||
"rand_core", |
||||
"rand_hc", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand_chacha" |
||||
version = "0.2.2" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" |
||||
dependencies = [ |
||||
"ppv-lite86", |
||||
"rand_core", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand_core" |
||||
version = "0.5.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" |
||||
dependencies = [ |
||||
"getrandom", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "rand_hc" |
||||
version = "0.2.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" |
||||
dependencies = [ |
||||
"rand_core", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "redox_syscall" |
||||
version = "0.1.57" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" |
||||
|
||||
[[package]] |
||||
name = "regex" |
||||
version = "1.4.2" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c" |
||||
dependencies = [ |
||||
"aho-corasick", |
||||
"memchr", |
||||
"regex-syntax", |
||||
"thread_local", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "regex-syntax" |
||||
version = "0.6.21" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" |
||||
|
||||
[[package]] |
||||
name = "remove_dir_all" |
||||
version = "0.5.3" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" |
||||
dependencies = [ |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "ryu" |
||||
version = "1.0.5" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" |
||||
|
||||
[[package]] |
||||
name = "same-file" |
||||
version = "1.0.6" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" |
||||
dependencies = [ |
||||
"winapi-util", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "serde" |
||||
version = "1.0.118" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800" |
||||
dependencies = [ |
||||
"serde_derive", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "serde_derive" |
||||
version = "1.0.118" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df" |
||||
dependencies = [ |
||||
"proc-macro2", |
||||
"quote", |
||||
"syn", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "serde_json" |
||||
version = "1.0.60" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "1500e84d27fe482ed1dc791a56eddc2f230046a040fa908c08bda1d9fb615779" |
||||
dependencies = [ |
||||
"itoa", |
||||
"ryu", |
||||
"serde", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "syn" |
||||
version = "1.0.55" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "a571a711dddd09019ccc628e1b17fe87c59b09d513c06c026877aa708334f37a" |
||||
dependencies = [ |
||||
"proc-macro2", |
||||
"quote", |
||||
"unicode-xid", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "tempfile" |
||||
version = "3.1.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" |
||||
dependencies = [ |
||||
"cfg-if 0.1.10", |
||||
"libc", |
||||
"rand", |
||||
"redox_syscall", |
||||
"remove_dir_all", |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "thread_local" |
||||
version = "1.0.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" |
||||
dependencies = [ |
||||
"lazy_static", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "treeline" |
||||
version = "0.1.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" |
||||
|
||||
[[package]] |
||||
name = "unicode-xid" |
||||
version = "0.2.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" |
||||
|
||||
[[package]] |
||||
name = "walkdir" |
||||
version = "2.3.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" |
||||
dependencies = [ |
||||
"same-file", |
||||
"winapi", |
||||
"winapi-util", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "wasi" |
||||
version = "0.9.0+wasi-snapshot-preview1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" |
||||
|
||||
[[package]] |
||||
name = "winapi" |
||||
version = "0.3.9" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" |
||||
dependencies = [ |
||||
"winapi-i686-pc-windows-gnu", |
||||
"winapi-x86_64-pc-windows-gnu", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "winapi-i686-pc-windows-gnu" |
||||
version = "0.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" |
||||
|
||||
[[package]] |
||||
name = "winapi-util" |
||||
version = "0.1.5" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" |
||||
dependencies = [ |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "winapi-x86_64-pc-windows-gnu" |
||||
version = "0.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "doubtful_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
doubtful = { path = "../../../../rust-piscine-solutions/doubtful" } |
@ -1,31 +0,0 @@
|
||||
/* |
||||
## doubtful |
||||
|
||||
### Instructions |
||||
|
||||
Write a function called `doubtful` that adds to every string passed |
||||
to it a question mark (?) |
||||
|
||||
You have to fix the code to make it compile an for that you can |
||||
only modify the code where is indicated |
||||
*/ |
||||
|
||||
use doubtful::*; |
||||
|
||||
fn main() { |
||||
let mut s = String::from("Hello"); |
||||
|
||||
println!("Before changing the string: {}", s); |
||||
doubtful(&mut s); |
||||
println!("After changing the string: {}", s); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_function() { |
||||
let mut s = "hello".to_string(); |
||||
let s_copy = s.clone(); |
||||
|
||||
doubtful(&mut s); |
||||
|
||||
assert_eq!(s, s_copy + "?"); |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "drop_the_thread" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "drop_the_thread_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"drop_the_thread", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "drop_the_thread_test" |
||||
version = "0.1.0" |
||||
authors = ["lee <lee-dasilva@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
drop_the_thread = { path = "../../../../rust-piscine-solutions/drop_the_thread"} |
@ -1,87 +0,0 @@
|
||||
use drop_the_thread::*; |
||||
use std::rc::Rc; |
||||
|
||||
fn main() { |
||||
let worker = Workers::new(); |
||||
let (id, thread) = worker.new_worker(String::from("command")); |
||||
let (id1, thread1) = worker.new_worker(String::from("command1")); |
||||
|
||||
thread.skill(); |
||||
|
||||
println!("{:?}", (worker.is_dropped(id), id, &worker.drops)); |
||||
// output: (true, 0, Cell { value: 1 })
|
||||
|
||||
thread1.skill(); |
||||
println!("{:?}", (worker.is_dropped(id1), id1, &worker.drops)); |
||||
// output: (true, 1, Cell { value: 2 })
|
||||
|
||||
let (id2, thread2) = worker.new_worker(String::from("command2")); |
||||
let thread2 = Rc::new(thread2); |
||||
let thread2_clone = thread2.clone(); |
||||
|
||||
// thread2_clone.skill();
|
||||
drop(thread2_clone); |
||||
|
||||
println!("{:?}", (worker.is_dropped(id2), id2, &worker.drops, Rc::strong_count(&thread2))); |
||||
// (false, 2, Cell { value: 2 }, 1)
|
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
use std::rc::Rc; |
||||
|
||||
#[test] |
||||
fn test_is_dropped_and_drops() { |
||||
let worker = Workers::new(); |
||||
let (pid, thread) = worker.new_worker(String::from("gnome-shell")); |
||||
let (pid0, thread0) = worker.new_worker(String::from("i3")); |
||||
let (pid1, thread1) = worker.new_worker(String::from("shell")); |
||||
let (pid2, thread2) = worker.new_worker(String::from("spotify")); |
||||
|
||||
thread.skill(); |
||||
assert_eq!(worker.drops.get(), 1_usize); |
||||
thread0.skill(); |
||||
|
||||
assert!(worker.is_dropped(pid), "{} should have been dropped", pid); |
||||
assert!(worker.is_dropped(pid0), "{} should have been dropped", pid0); |
||||
assert!(!worker.is_dropped(pid1), "{} should not have been dropped", pid1); |
||||
assert!(!worker.is_dropped(pid2), "{} should not have been dropped", pid2); |
||||
|
||||
assert_eq!(worker.drops.get(), 2_usize); |
||||
|
||||
thread1.skill(); |
||||
thread2.skill(); |
||||
|
||||
assert_eq!(worker.drops.get(), 4_usize); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_using_rc() { |
||||
// will create a new reference to the thread
|
||||
// this will test the following
|
||||
// if we drop the cloned value the RC will decrease
|
||||
// but the thread will not be dropped!
|
||||
let worker = Workers::new(); |
||||
let (_, thread) = worker.new_worker(String::from("Xorg")); |
||||
let thread = Rc::new(thread); |
||||
let thread_clone = thread.clone(); |
||||
|
||||
assert_eq!(Rc::strong_count(&thread), 2); |
||||
|
||||
drop(thread_clone); |
||||
|
||||
assert_eq!(Rc::strong_count(&thread), 1); |
||||
} |
||||
|
||||
#[test] |
||||
#[should_panic(expected = "0 is already dropped")] |
||||
fn test_drop_same_thread() { |
||||
// test if we drop the same thread after it was already been dropped
|
||||
let worker = Workers::new(); |
||||
let (pid, thread) = worker.new_worker(String::from("gsd-rfkill")); |
||||
let thread_clone = thread.clone(); |
||||
thread.skill(); |
||||
thread_clone.skill(); |
||||
} |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "edit_distance" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "edit_distance_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"edit_distance", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "edit_distance_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
edit_distance = { path = "../../../../rust-piscine-solutions/edit_distance"} |
@ -1,70 +0,0 @@
|
||||
// Create a function call `edit_distance` that calculates the minimum
|
||||
// number of changes (insertion, deletions and substitutions) that
|
||||
// need to be made to a string `source` to arrive to another `target`
|
||||
// string
|
||||
|
||||
// For more information and examples https://en.wikipedia.org/wiki/Edit_distance
|
||||
|
||||
// pub fn edit_distance(source: &str, target: &str) -> usize {
|
||||
// let src = source.chars().collect::<Vec<_>>();
|
||||
// let tar = target.chars().collect::<Vec<_>>();
|
||||
// let source_len = src.len() + 1;
|
||||
// let target_len = tar.len() + 1;
|
||||
|
||||
// if source_len == 0 {
|
||||
// return target_len;
|
||||
// }
|
||||
// if target_len == 0 {
|
||||
// return source_len;
|
||||
// }
|
||||
|
||||
// let mut matrix = vec![vec![0; source_len]; target_len];
|
||||
|
||||
// for i in 1..target_len {
|
||||
// matrix[i][0] = i
|
||||
// }
|
||||
// for j in 1..source_len {
|
||||
// matrix[0][j] = j
|
||||
// }
|
||||
|
||||
// for i in 1..target_len {
|
||||
// for j in 1..source_len {
|
||||
// let x = if src[j - 1] == tar[i - 1] {
|
||||
// matrix[i - 1][j - 1]
|
||||
// } else {
|
||||
// 1 + std::cmp::min(
|
||||
// std::cmp::min(matrix[i][j - 1], matrix[i - 1][j]),
|
||||
// matrix[i - 1][j - 1],
|
||||
// )
|
||||
// };
|
||||
// matrix[i][j] = x;
|
||||
// }
|
||||
// }
|
||||
// matrix[target_len - 1][source_len - 1]
|
||||
// }
|
||||
|
||||
use edit_distance::edit_distance; |
||||
|
||||
#[allow(dead_code)] |
||||
fn main() { |
||||
let source = "alignment"; |
||||
let target = "assignment"; |
||||
println!( |
||||
"It's necessary to make {} change(s) to {}, to get {}", |
||||
edit_distance(source, target), |
||||
source, |
||||
target |
||||
); |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod test { |
||||
use super::*; |
||||
|
||||
#[test] |
||||
fn test_distance() { |
||||
assert_eq!(edit_distance("gumbo", "gambol"), 2); |
||||
assert_eq!(edit_distance("kitten", "sitting"), 3); |
||||
assert_eq!(edit_distance("rosettacode", "raisethysword"), 8); |
||||
} |
||||
} |
@ -1,98 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "autocfg" |
||||
version = "1.0.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" |
||||
|
||||
[[package]] |
||||
name = "chrono" |
||||
version = "0.4.19" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" |
||||
dependencies = [ |
||||
"libc", |
||||
"num-integer", |
||||
"num-traits", |
||||
"time", |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "error_type" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"chrono", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "error_type_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"error_type", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "libc" |
||||
version = "0.2.81" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" |
||||
|
||||
[[package]] |
||||
name = "num-integer" |
||||
version = "0.1.44" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" |
||||
dependencies = [ |
||||
"autocfg", |
||||
"num-traits", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "num-traits" |
||||
version = "0.2.14" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" |
||||
dependencies = [ |
||||
"autocfg", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "time" |
||||
version = "0.1.44" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" |
||||
dependencies = [ |
||||
"libc", |
||||
"wasi", |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "wasi" |
||||
version = "0.10.0+wasi-snapshot-preview1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" |
||||
|
||||
[[package]] |
||||
name = "winapi" |
||||
version = "0.3.9" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" |
||||
dependencies = [ |
||||
"winapi-i686-pc-windows-gnu", |
||||
"winapi-x86_64-pc-windows-gnu", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "winapi-i686-pc-windows-gnu" |
||||
version = "0.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" |
||||
|
||||
[[package]] |
||||
name = "winapi-x86_64-pc-windows-gnu" |
||||
version = "0.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "error_type_test" |
||||
version = "0.1.0" |
||||
authors = ["lee <lee-dasilva@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
error_type = { path = "../../../../rust-piscine-solutions/error_type"} |
@ -1,136 +0,0 @@
|
||||
use error_type::*; |
||||
|
||||
#[allow(dead_code)] |
||||
fn create_date(date: &str) -> NaiveDate { |
||||
NaiveDate::parse_from_str(date, "%Y-%m-%d").unwrap() |
||||
} |
||||
|
||||
fn main() { |
||||
let mut form_output = Form::new( |
||||
String::from("Lee"), |
||||
String::from("Silva"), |
||||
create_date("2015-09-05"), |
||||
SexType::Male, |
||||
String::from("Africa"), |
||||
String::from("qwqwsa1dty_")); |
||||
|
||||
println!("{:?}", form_output); |
||||
println!("{:?}", form_output.validate().unwrap()); |
||||
|
||||
form_output.first_name = String::from(""); |
||||
println!("{:?}", form_output.validate().unwrap_err()); |
||||
|
||||
form_output.first_name = String::from("as"); |
||||
form_output.password = String::from("dty_1"); |
||||
println!("{:?}", form_output.validate().unwrap_err()); |
||||
|
||||
form_output.password = String::from("asdasASd(_"); |
||||
println!("{:?}", form_output.validate().unwrap_err()); |
||||
|
||||
form_output.password = String::from("asdasASd123SA"); |
||||
println!("{:?}", form_output.validate().unwrap_err()); |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
|
||||
#[derive(Debug)] |
||||
struct TestForm<'a> { |
||||
form: Form, |
||||
validation: Result<Vec<&'a str>, FErr> |
||||
} |
||||
|
||||
impl <'a> TestForm<'_> { |
||||
// all test cases
|
||||
fn new() -> Vec<TestForm<'a>> { |
||||
vec![ |
||||
TestForm { |
||||
form : Form::new( |
||||
String::from("Katy"), |
||||
String::from("Silva"), |
||||
create_date("2015-09-05"), |
||||
SexType::Female, |
||||
String::from("Africa"), |
||||
String::from("qwTw12&%$3sa1dty_")), |
||||
validation: Ok(vec!["Valid first name", "Valid password"]), |
||||
}, |
||||
TestForm { |
||||
form : Form::new( |
||||
String::from(""), |
||||
String::from("Bear"), |
||||
create_date("2015-09-05"), |
||||
SexType::Male, |
||||
String::from("Africa"), |
||||
String::from("qwTw12&%$3sa1dty_")), |
||||
validation: Err(FErr { |
||||
form_values: (String::from("first_name"), |
||||
String::from("")), |
||||
date: Utc::now().format("%Y-%m-%d %H:%M:%S").to_string(), |
||||
err: String::from("No user name")}), |
||||
}, |
||||
TestForm { |
||||
form : Form::new( |
||||
String::from("Someone"), |
||||
String::from("Bear"), |
||||
create_date("2015-09-05"), |
||||
SexType::Male, |
||||
String::from("Africa"), |
||||
String::from("12345")), |
||||
validation: Err(FErr { |
||||
form_values: (String::from("password"), String::from("12345")), |
||||
date: Utc::now().format("%Y-%m-%d %H:%M:%S").to_string(), |
||||
err: String::from("At least 8 characters") }), |
||||
}, |
||||
TestForm { |
||||
form : Form::new( |
||||
String::from("Someone"), |
||||
String::from("Bear"), |
||||
create_date("2015-09-05"), |
||||
SexType::Male, |
||||
String::from("Africa"), |
||||
String::from("sdASDsrW")), |
||||
validation: Err(FErr { |
||||
form_values: (String::from("password"), String::from("sdASDsrW")), |
||||
date: Utc::now().format("%Y-%m-%d %H:%M:%S").to_string(), |
||||
err: String::from("Combination of different ASCII character types (numbers, letters and none alphanumeric characters)") }), |
||||
}, |
||||
TestForm { |
||||
form : Form::new( |
||||
String::from("Someone"), |
||||
String::from("Bear"), |
||||
create_date("2015-09-05"), |
||||
SexType::Female, |
||||
String::from("Africa"), |
||||
String::from("dsGE1SAD213")), |
||||
validation: Err(FErr { |
||||
form_values: (String::from("password"), String::from("dsGE1SAD213")), |
||||
date: Utc::now().format("%Y-%m-%d %H:%M:%S").to_string(), |
||||
err: String::from("Combination of different ASCII character types (numbers, letters and none alphanumeric characters)") }), |
||||
}, |
||||
TestForm { |
||||
form : Form::new( |
||||
String::from("Someone"), |
||||
String::from("Bear"), |
||||
create_date("2015-09-05"), |
||||
SexType::Female, |
||||
String::from("Africa"), |
||||
String::from("dsaSD&%DF!?=")), |
||||
validation: Err(FErr { |
||||
form_values: (String::from("password"), String::from("dsaSD&%DF!?=")), |
||||
date: Utc::now().format("%Y-%m-%d %H:%M:%S").to_string(), |
||||
err: String::from("Combination of different ASCII character types (numbers, letters and none alphanumeric characters)") }), |
||||
} |
||||
] |
||||
} |
||||
} |
||||
|
||||
#[test] |
||||
fn test_error_type() { |
||||
let form_cases = TestForm::new(); |
||||
|
||||
for v in form_cases { |
||||
assert_eq!(v.form.validate(), v.validation); |
||||
} |
||||
} |
||||
} |
@ -1,138 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "atty" |
||||
version = "0.2.14" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" |
||||
dependencies = [ |
||||
"hermit-abi", |
||||
"libc", |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "autocfg" |
||||
version = "1.0.1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" |
||||
|
||||
[[package]] |
||||
name = "chrono" |
||||
version = "0.4.19" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" |
||||
dependencies = [ |
||||
"libc", |
||||
"num-integer", |
||||
"num-traits", |
||||
"time", |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "colored" |
||||
version = "2.0.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" |
||||
dependencies = [ |
||||
"atty", |
||||
"lazy_static", |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "events" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"chrono", |
||||
"colored", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "events_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"chrono", |
||||
"colored", |
||||
"events", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "hermit-abi" |
||||
version = "0.1.17" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" |
||||
dependencies = [ |
||||
"libc", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "lazy_static" |
||||
version = "1.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" |
||||
|
||||
[[package]] |
||||
name = "libc" |
||||
version = "0.2.81" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" |
||||
|
||||
[[package]] |
||||
name = "num-integer" |
||||
version = "0.1.44" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" |
||||
dependencies = [ |
||||
"autocfg", |
||||
"num-traits", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "num-traits" |
||||
version = "0.2.14" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" |
||||
dependencies = [ |
||||
"autocfg", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "time" |
||||
version = "0.1.44" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" |
||||
dependencies = [ |
||||
"libc", |
||||
"wasi", |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "wasi" |
||||
version = "0.10.0+wasi-snapshot-preview1" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" |
||||
|
||||
[[package]] |
||||
name = "winapi" |
||||
version = "0.3.9" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" |
||||
dependencies = [ |
||||
"winapi-i686-pc-windows-gnu", |
||||
"winapi-x86_64-pc-windows-gnu", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "winapi-i686-pc-windows-gnu" |
||||
version = "0.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" |
||||
|
||||
[[package]] |
||||
name = "winapi-x86_64-pc-windows-gnu" |
||||
version = "0.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" |
@ -1,12 +0,0 @@
|
||||
[package] |
||||
name = "events_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
chrono = "0.4" |
||||
colored = "2" |
||||
events = { path = "../../../../rust-piscine-solutions/events"} |
@ -1,141 +0,0 @@
|
||||
// You're have to design a notification system for a platform
|
||||
// This events are Remainders, Registrations, Appointments, Holidays
|
||||
// Create an event handler that depending of the type of event creates
|
||||
// different notification: different color, different size and
|
||||
// different position
|
||||
|
||||
// The possible positions are Top, Bottom and Center: Create and Enum
|
||||
// `Position` with those values
|
||||
|
||||
// Create a struct called `Notification` with the fields
|
||||
// size: u32,
|
||||
// color: (u8, u8, u8),
|
||||
// position: Position,
|
||||
// content: String,
|
||||
|
||||
// The event that you have to handle are
|
||||
// enum Event {
|
||||
// Remainder(&str),
|
||||
// Registration(Duration),
|
||||
// Appointment(&str),
|
||||
// Holiday,
|
||||
// }
|
||||
|
||||
// Create a method called `notify`
|
||||
// fn notify(&self) -> Notification
|
||||
// That returns a notification with the following caracteristics for
|
||||
// each
|
||||
// Remainder:
|
||||
// size= 50,
|
||||
// color= (50, 50, 50),
|
||||
// position= Bottom,
|
||||
// content= the slice associated to the enum value
|
||||
|
||||
// Registration(chrono::Duration),
|
||||
// size = 30,
|
||||
// color = (255, 2, 22),
|
||||
// position = Top,
|
||||
// content = "You have `duration` left before the registration ends",
|
||||
// `durations` must be displayed in the form of
|
||||
// {hours}:{minutes}:{seconds} left for the beginning of the event
|
||||
// for example if there is two hours 32 minutes and 3 seconds left
|
||||
// before the registration then the content will be `You have 2:32:2 left before the registration ends`
|
||||
|
||||
// Appointment(text)
|
||||
// size: 100
|
||||
// color: (200, 200, 3)
|
||||
// position: Center
|
||||
// content: text associated to the value
|
||||
|
||||
// Holiday
|
||||
// size: 25
|
||||
// color: (0, 255, 0)
|
||||
// position: Top
|
||||
// content: "Enjoy your holiday"
|
||||
|
||||
use chrono::Duration; |
||||
use events::Event::*; |
||||
#[allow(unused_imports)] |
||||
use events::{Notification, Position}; |
||||
|
||||
#[allow(dead_code)] |
||||
fn main() { |
||||
let remainder = Remainder("Go to the doctor"); |
||||
println!("{}", remainder.notify()); |
||||
let registration = Registration(Duration::seconds(49094)); |
||||
println!("{}", registration.notify()); |
||||
let appointment = Appointment("Go to the doctor"); |
||||
println!("{}", appointment.notify()); |
||||
let holiday = Holiday; |
||||
println!("{}", holiday.notify()); |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
|
||||
use super::*; |
||||
|
||||
#[test] |
||||
fn remainder_notification() { |
||||
let remainder = Remainder("Go to the doctor"); |
||||
let notification = remainder.notify(); |
||||
println!("{}", ¬ification); |
||||
assert_eq!( |
||||
notification, |
||||
Notification { |
||||
size: 50, |
||||
color: (50, 50, 50), |
||||
position: Position::Bottom, |
||||
content: "Go to the doctor".to_string(), |
||||
} |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
fn registration_notification() { |
||||
let registration = Registration(Duration::seconds(49094)); |
||||
let notification = registration.notify(); |
||||
println!("{}", registration.notify()); |
||||
assert_eq!( |
||||
notification, |
||||
Notification { |
||||
size: 30, |
||||
color: (255, 2, 22), |
||||
position: Position::Top, |
||||
content: "You have 13H:38M:14S left before the registration ends".to_string(), |
||||
} |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
fn appointment_notification() { |
||||
let appointment = Appointment("Go to the doctor"); |
||||
let notification = appointment.notify(); |
||||
println!("{}", ¬ification); |
||||
assert_eq!( |
||||
notification, |
||||
Notification { |
||||
size: 100, |
||||
color: (200, 200, 3), |
||||
position: Position::Center, |
||||
content: "Go to the doctor".to_string(), |
||||
} |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
fn holiday_notification() { |
||||
let holiday = Holiday; |
||||
let notification = Holiday.notify(); |
||||
println!("{}", holiday.notify()); |
||||
assert_eq!( |
||||
notification, |
||||
Notification { |
||||
size: 25, |
||||
color: (0, 255, 0), |
||||
position: Position::Top, |
||||
content: String::from("Enjoy your holiday"), |
||||
} |
||||
); |
||||
} |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "fibonacci2" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "fibonacci2_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"fibonacci2", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "fibonacci2_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
fibonacci2 = {path = "../../../../rust-piscine-solutions/fibonacci2"} |
@ -1,32 +0,0 @@
|
||||
use fibonacci2::*; |
||||
|
||||
fn main() { |
||||
println!( |
||||
"The element in the position {} in fibonacci series is {}", |
||||
2, |
||||
fibonacci(2) |
||||
); |
||||
println!( |
||||
"The element in the position {} in fibonacci series is {}", |
||||
4, |
||||
fibonacci(4) |
||||
); |
||||
println!( |
||||
"The element in the position {} in fibonacci series is {}", |
||||
22, |
||||
fibonacci(22) |
||||
); |
||||
println!( |
||||
"The element in the position {} in fibonacci series is {}", |
||||
20, |
||||
fibonacci(20) |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
fn it_works() { |
||||
assert_eq!(fibonacci(0), 0); |
||||
assert_eq!(fibonacci(1), 1); |
||||
assert_eq!(fibonacci(22), 17711); |
||||
assert_eq!(fibonacci(20), 6765); |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "find_factorial" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "find_factorial_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"find_factorial", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "find_factorial_test" |
||||
version = "0.1.0" |
||||
authors = ["MSilva95 <miguel-silva98@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
find_factorial = { path = "../../../../rust-piscine-solutions/find_factorial"} |
@ -1,35 +0,0 @@
|
||||
// Complete this function to return the factorial of a given number
|
||||
use find_factorial::*; |
||||
|
||||
pub fn factorial(num: u64) -> u64 { |
||||
match num { |
||||
0 | 1 => 1, |
||||
_ => factorial(num - 1) * num, |
||||
} |
||||
} |
||||
|
||||
fn main() { |
||||
println!("The factorial of 0 = {}", factorial(0));
|
||||
println!("The factorial of 1 = {}", factorial(1));
|
||||
println!("The factorial of 5 = {}", factorial(5));
|
||||
println!("The factorial of 10 = {}", factorial(10));
|
||||
println!("The factorial of 19 = {}", factorial(19));
|
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
|
||||
#[test] |
||||
fn factorial_of_1() { |
||||
assert_eq!(1, factorial(0)); |
||||
assert_eq!(1, factorial(1)); |
||||
assert_eq!(120, factorial(5)); |
||||
assert_eq!(40320, factorial(8)); |
||||
assert_eq!(3628800, factorial(10)); |
||||
assert_eq!(87178291200, factorial(14)); |
||||
assert_eq!(6402373705728000, factorial(18)); |
||||
assert_eq!(121645100408832000, factorial(19)); |
||||
assert_eq!(2432902008176640000, factorial(20)); |
||||
} |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "generics" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "generics_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"generics", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "generics_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
generics = { path = "../../../../rust-piscine-solutions/generics"} |
@ -1,35 +0,0 @@
|
||||
// Write a functions called identity that calculates the identity of a
|
||||
// value (receives any data type and returns the same value)
|
||||
use generics::*; |
||||
|
||||
fn main() { |
||||
println!("{}", identity("Hello, world!")); |
||||
println!("{}", identity(3)); |
||||
} |
||||
|
||||
#[derive(PartialEq, Debug)] |
||||
struct Point { |
||||
x: i32, |
||||
y: i32, |
||||
} |
||||
|
||||
#[test] |
||||
fn test_with_int() { |
||||
assert_eq!(identity(3), 3); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_with_float() { |
||||
assert_eq!(identity(1.0), 1.0); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_with_str() { |
||||
assert_eq!(identity("you"), "you"); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_with_struct() { |
||||
let s = Point { x: 1, y: 2 }; |
||||
assert_eq!(identity(&s), &s); |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "get_products" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "get_products_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"get_products", |
||||
] |
@ -1,10 +0,0 @@
|
||||
[package] |
||||
name = "get_products_test" |
||||
version = "0.1.0" |
||||
authors = ["MSilva95 <miguel-silva98@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
get_products = { path = "../../../../rust-piscine-solutions/get_products"} |
@ -1,49 +0,0 @@
|
||||
/* |
||||
## get_products |
||||
|
||||
### Instructions |
||||
|
||||
Create a function `get_products` that takes a vector of integers, and returns a vector of the products |
||||
of each index. For this exercise to be correct you will have to return the product of every index |
||||
except the current one. |
||||
|
||||
### Example: |
||||
|
||||
Input: arr[] = {10, 3, 5, 6, 2} |
||||
Output: prod[] = {180, 600, 360, 300, 900} |
||||
|
||||
*/ |
||||
use get_products::*; |
||||
fn main() { |
||||
let arr: Vec<usize> = vec![1, 7, 3, 4]; |
||||
let output = get_products(arr); |
||||
println!("{:?}", output); |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
#[test] |
||||
fn test_multiple() { |
||||
let arr: Vec<usize> = vec![1, 7, 3, 4]; |
||||
let output = get_products(arr); |
||||
let arr2: Vec<usize> = vec![10, 3, 5, 6, 2]; |
||||
let output2 = get_products(arr2); |
||||
assert_eq!(output, vec![84, 12, 28, 21]); |
||||
assert_eq!(output2, vec![180, 600, 360, 300, 900]); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_empty_case() { |
||||
let arr: Vec<usize> = Vec::new(); |
||||
let output = get_products(arr); |
||||
assert_eq!(output, vec![]); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_single_case() { |
||||
let arr: Vec<usize> = vec![2]; |
||||
let output = get_products(arr); |
||||
assert_eq!(output, vec![]); |
||||
} |
||||
} |
@ -1,12 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "groceries" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "groceries_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"groceries", |
||||
] |
Some files were not shown because too many files changed in this diff diff.show_more
Loading…
Reference in new issue