diff --git a/rust/tests/adding_test/Cargo.lock b/rust/tests/adding_test/Cargo.lock deleted file mode 100644 index 8423c820..00000000 --- a/rust/tests/adding_test/Cargo.lock +++ /dev/null @@ -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", -] - diff --git a/rust/tests/adding_test/Cargo.toml b/rust/tests/adding_test/Cargo.toml deleted file mode 100644 index 9fd50d5a..00000000 --- a/rust/tests/adding_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "adding_test" -version = "0.1.0" -authors = ["MSilva95 "] -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"} diff --git a/rust/tests/adding_test/src/main.rs b/rust/tests/adding_test/src/main.rs deleted file mode 100644 index 98647e84..00000000 --- a/rust/tests/adding_test/src/main.rs +++ /dev/null @@ -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); - } -} diff --git a/rust/tests/adding_twice_test/Cargo.lock b/rust/tests/adding_twice_test/Cargo.lock deleted file mode 100644 index 74532f0d..00000000 --- a/rust/tests/adding_twice_test/Cargo.lock +++ /dev/null @@ -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", -] - diff --git a/rust/tests/adding_twice_test/Cargo.toml b/rust/tests/adding_twice_test/Cargo.toml deleted file mode 100644 index ae6e76ce..00000000 --- a/rust/tests/adding_twice_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "adding_twice_test" -version = "0.1.0" -authors = ["MSilva95 "] -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"} diff --git a/rust/tests/adding_twice_test/src/main.rs b/rust/tests/adding_twice_test/src/main.rs deleted file mode 100644 index e6febb29..00000000 --- a/rust/tests/adding_twice_test/src/main.rs +++ /dev/null @@ -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); - } -} diff --git a/rust/tests/arrange_it_test/Cargo.lock b/rust/tests/arrange_it_test/Cargo.lock deleted file mode 100644 index a0ded1a4..00000000 --- a/rust/tests/arrange_it_test/Cargo.lock +++ /dev/null @@ -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" diff --git a/rust/tests/arrange_it_test/Cargo.toml b/rust/tests/arrange_it_test/Cargo.toml deleted file mode 100644 index 03acd1f9..00000000 --- a/rust/tests/arrange_it_test/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "arrange_it_test" -version = "0.1.0" -authors = ["lee "] -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"} \ No newline at end of file diff --git a/rust/tests/arrange_it_test/src/main.rs b/rust/tests/arrange_it_test/src/main.rs deleted file mode 100644 index 242334f6..00000000 --- a/rust/tests/arrange_it_test/src/main.rs +++ /dev/null @@ -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 = 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::(); -// } -// } -// } -// 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::().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)); - } -} diff --git a/rust/tests/arrays_test/Cargo.lock b/rust/tests/arrays_test/Cargo.lock deleted file mode 100644 index cfa529ad..00000000 --- a/rust/tests/arrays_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/arrays_test/Cargo.toml b/rust/tests/arrays_test/Cargo.toml deleted file mode 100644 index a2d24025..00000000 --- a/rust/tests/arrays_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "arrays_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -arrays = { path = "../../../../rust-piscine-solutions/arrays"} \ No newline at end of file diff --git a/rust/tests/arrays_test/src/main.rs b/rust/tests/arrays_test/src/main.rs deleted file mode 100644 index e41ac452..00000000 --- a/rust/tests/arrays_test/src/main.rs +++ /dev/null @@ -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 = (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()); -} diff --git a/rust/tests/banner_test/Cargo.lock b/rust/tests/banner_test/Cargo.lock deleted file mode 100644 index 585ef531..00000000 --- a/rust/tests/banner_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/banner_test/Cargo.toml b/rust/tests/banner_test/Cargo.toml deleted file mode 100644 index 7f992125..00000000 --- a/rust/tests/banner_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "banner_test" -version = "0.1.0" -authors = ["lee "] -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"} diff --git a/rust/tests/banner_test/src/main.rs b/rust/tests/banner_test/src/main.rs deleted file mode 100644 index c0500785..00000000 --- a/rust/tests/banner_test/src/main.rs +++ /dev/null @@ -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" - ); - } -} - diff --git a/rust/tests/bigger_test/Cargo.lock b/rust/tests/bigger_test/Cargo.lock deleted file mode 100644 index ae68ba5a..00000000 --- a/rust/tests/bigger_test/Cargo.lock +++ /dev/null @@ -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" diff --git a/rust/tests/bigger_test/Cargo.toml b/rust/tests/bigger_test/Cargo.toml deleted file mode 100644 index b2e2a940..00000000 --- a/rust/tests/bigger_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "bigger_test" -version = "0.1.0" -authors = ["MSilva95 "] -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"} \ No newline at end of file diff --git a/rust/tests/bigger_test/src/main.rs b/rust/tests/bigger_test/src/main.rs deleted file mode 100644 index 01625968..00000000 --- a/rust/tests/bigger_test/src/main.rs +++ /dev/null @@ -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)); -} diff --git a/rust/tests/blood_types_test/Cargo.lock b/rust/tests/blood_types_test/Cargo.lock deleted file mode 100644 index aa4b693b..00000000 --- a/rust/tests/blood_types_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/blood_types_test/Cargo.toml b/rust/tests/blood_types_test/Cargo.toml deleted file mode 100644 index e90cec5d..00000000 --- a/rust/tests/blood_types_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "blood_types_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -blood_types = { path = "../../../../rust-piscine-solutions/blood_types"} diff --git a/rust/tests/blood_types_test/src/main.rs b/rust/tests/blood_types_test/src/main.rs deleted file mode 100644 index 260cd8ba..00000000 --- a/rust/tests/blood_types_test/src/main.rs +++ /dev/null @@ -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: which returns -// all the blood types that can give blood to self -// - recipients(&self) -> Vec: 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::().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::().unwrap().donors(); - println!("Before sorting {:?}", &givers); - givers.sort(); - println!("{:?}", &givers); - let mut expected = vec![ - "AB-".parse::().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::().unwrap().donors(); - givers.sort(); - let mut expected: Vec = vec!["A-".parse().unwrap(), "O-".parse().unwrap()]; - expected.sort(); - assert_eq!(givers, expected); -} - -#[test] -fn test_o_neg_donors() { - let mut givers = "O-".parse::().unwrap().donors(); - givers.sort(); - let mut expected: Vec = vec!["O-".parse().unwrap()]; - expected.sort(); - assert_eq!(givers, expected); -} - -#[test] -fn test_ab_pos_recipients() { - let mut recipients: Vec = "AB+".parse::().unwrap().recipients(); - recipients.sort(); - let mut expected: Vec = vec!["AB+".parse().unwrap()]; - expected.sort(); - assert_eq!(recipients, expected); -} - -#[test] -fn test_a_neg_recipients() { - let mut recipients = "A-".parse::().unwrap().recipients(); - recipients.sort(); - let mut expected: Vec = 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) - ); -} diff --git a/rust/tests/borrow_box_test/Cargo.lock b/rust/tests/borrow_box_test/Cargo.lock deleted file mode 100644 index c1ff1ef0..00000000 --- a/rust/tests/borrow_box_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/borrow_box_test/Cargo.toml b/rust/tests/borrow_box_test/Cargo.toml deleted file mode 100644 index 9d448ad9..00000000 --- a/rust/tests/borrow_box_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "borrow_box_test" -version = "0.1.0" -authors = ["lee "] -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"} diff --git a/rust/tests/borrow_box_test/src/main.rs b/rust/tests/borrow_box_test/src/main.rs deleted file mode 100644 index beed0141..00000000 --- a/rust/tests/borrow_box_test/src/main.rs +++ /dev/null @@ -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> { - 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); - // } - // } -} diff --git a/rust/tests/borrow_me_the_reference_test/Cargo.lock b/rust/tests/borrow_me_the_reference_test/Cargo.lock deleted file mode 100644 index c0769079..00000000 --- a/rust/tests/borrow_me_the_reference_test/Cargo.lock +++ /dev/null @@ -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" diff --git a/rust/tests/borrow_me_the_reference_test/Cargo.toml b/rust/tests/borrow_me_the_reference_test/Cargo.toml deleted file mode 100644 index 2880e3ec..00000000 --- a/rust/tests/borrow_me_the_reference_test/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "borrow_me_the_reference_test" -version = "0.1.0" -authors = ["lee "] -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"} diff --git a/rust/tests/borrow_me_the_reference_test/src/main.rs b/rust/tests/borrow_me_the_reference_test/src/main.rs deleted file mode 100644 index 1efb1863..00000000 --- a/rust/tests/borrow_me_the_reference_test/src/main.rs +++ /dev/null @@ -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::().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) -} diff --git a/rust/tests/borrow_test/Cargo.lock b/rust/tests/borrow_test/Cargo.lock deleted file mode 100644 index 0ca31837..00000000 --- a/rust/tests/borrow_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/borrow_test/Cargo.toml b/rust/tests/borrow_test/Cargo.toml deleted file mode 100644 index b13a6d97..00000000 --- a/rust/tests/borrow_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "borrow_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -borrow = { path = "../../../../rust-piscine-solutions/borrow"} \ No newline at end of file diff --git a/rust/tests/borrow_test/src/main.rs b/rust/tests/borrow_test/src/main.rs deleted file mode 100644 index c5200a71..00000000 --- a/rust/tests/borrow_test/src/main.rs +++ /dev/null @@ -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)); - } -} diff --git a/rust/tests/box_it_test/Cargo.lock b/rust/tests/box_it_test/Cargo.lock deleted file mode 100644 index f322a385..00000000 --- a/rust/tests/box_it_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/box_it_test/Cargo.toml b/rust/tests/box_it_test/Cargo.toml deleted file mode 100644 index 98d33050..00000000 --- a/rust/tests/box_it_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "box_it_test" -version = "0.1.0" -authors = ["lee "] -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"} diff --git a/rust/tests/box_it_test/src/main.rs b/rust/tests/box_it_test/src/main.rs deleted file mode 100644 index c69033f8..00000000 --- a/rust/tests/box_it_test/src/main.rs +++ /dev/null @@ -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); - } -} diff --git a/rust/tests/box_recursion_test/Cargo.lock b/rust/tests/box_recursion_test/Cargo.lock deleted file mode 100644 index 1e77a0dc..00000000 --- a/rust/tests/box_recursion_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/box_recursion_test/Cargo.toml b/rust/tests/box_recursion_test/Cargo.toml deleted file mode 100644 index db29730c..00000000 --- a/rust/tests/box_recursion_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "box_recursion_test" -version = "0.1.0" -authors = ["lee "] -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"} diff --git a/rust/tests/box_recursion_test/src/main.rs b/rust/tests/box_recursion_test/src/main.rs deleted file mode 100644 index 6de2aa07..00000000 --- a/rust/tests/box_recursion_test/src/main.rs +++ /dev/null @@ -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")) - ); - } -} diff --git a/rust/tests/boxing_todo_test/Cargo.lock b/rust/tests/boxing_todo_test/Cargo.lock deleted file mode 100644 index 7c71d7d5..00000000 --- a/rust/tests/boxing_todo_test/Cargo.lock +++ /dev/null @@ -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" diff --git a/rust/tests/boxing_todo_test/Cargo.toml b/rust/tests/boxing_todo_test/Cargo.toml deleted file mode 100644 index cd7019e9..00000000 --- a/rust/tests/boxing_todo_test/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "boxing_todo_test" -version = "0.1.0" -authors = ["lee "] -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" diff --git a/rust/tests/boxing_todo_test/src/main.rs b/rust/tests/boxing_todo_test/src/main.rs deleted file mode 100644 index 394a074f..00000000 --- a/rust/tests/boxing_todo_test/src/main.rs +++ /dev/null @@ -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) -> TodoList { - TodoList { title: s, tasks: v } - } - fn run(s: &TodoList, f: &str) -> Result> { - 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)); - } -} diff --git a/rust/tests/capitalizing_test/Cargo.lock b/rust/tests/capitalizing_test/Cargo.lock deleted file mode 100644 index 3d340e3f..00000000 --- a/rust/tests/capitalizing_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/capitalizing_test/Cargo.toml b/rust/tests/capitalizing_test/Cargo.toml deleted file mode 100644 index 92782bcf..00000000 --- a/rust/tests/capitalizing_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "capitalizing_test" -version = "0.1.0" -authors = ["MSilva95 "] -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"} diff --git a/rust/tests/capitalizing_test/src/main.rs b/rust/tests/capitalizing_test/src/main.rs deleted file mode 100644 index cf20b84b..00000000 --- a/rust/tests/capitalizing_test/src/main.rs +++ /dev/null @@ -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(""), ""); -} diff --git a/rust/tests/card_deck_test/Cargo.lock b/rust/tests/card_deck_test/Cargo.lock deleted file mode 100644 index 8c4fa4f8..00000000 --- a/rust/tests/card_deck_test/Cargo.lock +++ /dev/null @@ -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" diff --git a/rust/tests/card_deck_test/Cargo.toml b/rust/tests/card_deck_test/Cargo.toml deleted file mode 100644 index 88542de7..00000000 --- a/rust/tests/card_deck_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "card_deck_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -card_deck = { path = "../../../../rust-piscine-solutions/card_deck"} \ No newline at end of file diff --git a/rust/tests/card_deck_test/src/main.rs b/rust/tests/card_deck_test/src/main.rs deleted file mode 100644 index ccb20162..00000000 --- a/rust/tests/card_deck_test/src/main.rs +++ /dev/null @@ -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)); - } - } - } -} diff --git a/rust/tests/changes_test/Cargo.lock b/rust/tests/changes_test/Cargo.lock deleted file mode 100644 index b843d759..00000000 --- a/rust/tests/changes_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/changes_test/Cargo.toml b/rust/tests/changes_test/Cargo.toml deleted file mode 100644 index f2d5eb57..00000000 --- a/rust/tests/changes_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "changes_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -changes = { path = "../../../../rust-piscine-solutions/changes"} \ No newline at end of file diff --git a/rust/tests/changes_test/src/main.rs b/rust/tests/changes_test/src/main.rs deleted file mode 100644 index afe96a1b..00000000 --- a/rust/tests/changes_test/src/main.rs +++ /dev/null @@ -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); -} diff --git a/rust/tests/cipher_test/Cargo.lock b/rust/tests/cipher_test/Cargo.lock deleted file mode 100644 index fbb752c6..00000000 --- a/rust/tests/cipher_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/cipher_test/Cargo.toml b/rust/tests/cipher_test/Cargo.toml deleted file mode 100644 index 3d3c9f42..00000000 --- a/rust/tests/cipher_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "cipher_test" -version = "0.1.0" -authors = ["lee "] -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"} diff --git a/rust/tests/cipher_test/src/main.rs b/rust/tests/cipher_test/src/main.rs deleted file mode 100644 index 186fe157..00000000 --- a/rust/tests/cipher_test/src/main.rs +++ /dev/null @@ -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") }))); - } -} \ No newline at end of file diff --git a/rust/tests/circle_test/Cargo.lock b/rust/tests/circle_test/Cargo.lock deleted file mode 100644 index 72a8b713..00000000 --- a/rust/tests/circle_test/Cargo.lock +++ /dev/null @@ -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" diff --git a/rust/tests/circle_test/Cargo.toml b/rust/tests/circle_test/Cargo.toml deleted file mode 100644 index a648751e..00000000 --- a/rust/tests/circle_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "circle_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -circle = { path = "../../../../rust-piscine-solutions/circle"} \ No newline at end of file diff --git a/rust/tests/circle_test/src/main.rs b/rust/tests/circle_test/src/main.rs deleted file mode 100644 index e05821ba..00000000 --- a/rust/tests/circle_test/src/main.rs +++ /dev/null @@ -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)); -} diff --git a/rust/tests/closures_test/Cargo.lock b/rust/tests/closures_test/Cargo.lock deleted file mode 100644 index 4151173c..00000000 --- a/rust/tests/closures_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/closures_test/Cargo.toml b/rust/tests/closures_test/Cargo.toml deleted file mode 100644 index 064a1c7e..00000000 --- a/rust/tests/closures_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "closures_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -closures = { path = "../../../../rust-piscine-solutions/closures"} diff --git a/rust/tests/closures_test/src/main.rs b/rust/tests/closures_test/src/main.rs deleted file mode 100644 index d4c63e01..00000000 --- a/rust/tests/closures_test/src/main.rs +++ /dev/null @@ -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()); - } -} diff --git a/rust/tests/collect_test/Cargo.lock b/rust/tests/collect_test/Cargo.lock deleted file mode 100644 index be825328..00000000 --- a/rust/tests/collect_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/collect_test/Cargo.toml b/rust/tests/collect_test/Cargo.toml deleted file mode 100644 index 2fcf9a90..00000000 --- a/rust/tests/collect_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "collect_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -collect = { path = "../../../../rust-piscine-solutions/collect"} \ No newline at end of file diff --git a/rust/tests/collect_test/src/main.rs b/rust/tests/collect_test/src/main.rs deleted file mode 100644 index c5a1f8d4..00000000 --- a/rust/tests/collect_test/src/main.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Implement the function bubble_sort which receives a vector Vec -// 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); -} diff --git a/rust/tests/copy_test/Cargo.lock b/rust/tests/copy_test/Cargo.lock deleted file mode 100644 index 2639ed35..00000000 --- a/rust/tests/copy_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/copy_test/Cargo.toml b/rust/tests/copy_test/Cargo.toml deleted file mode 100644 index e28c6fc2..00000000 --- a/rust/tests/copy_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "copy_test" -version = "0.1.0" -authors = ["lee "] -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"} \ No newline at end of file diff --git a/rust/tests/copy_test/src/main.rs b/rust/tests/copy_test/src/main.rs deleted file mode 100644 index 468b2e5d..00000000 --- a/rust/tests/copy_test/src/main.rs +++ /dev/null @@ -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()))); -} diff --git a/rust/tests/delete_prefix_test/Cargo.lock b/rust/tests/delete_prefix_test/Cargo.lock deleted file mode 100644 index a2a55495..00000000 --- a/rust/tests/delete_prefix_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/delete_prefix_test/Cargo.toml b/rust/tests/delete_prefix_test/Cargo.toml deleted file mode 100644 index e1d7355e..00000000 --- a/rust/tests/delete_prefix_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "delete_prefix_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -delete_prefix = { path = "../../../../rust-piscine-solutions/delete_prefix"} \ No newline at end of file diff --git a/rust/tests/delete_prefix_test/src/main.rs b/rust/tests/delete_prefix_test/src/main.rs deleted file mode 100644 index c858421d..00000000 --- a/rust/tests/delete_prefix_test/src/main.rs +++ /dev/null @@ -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")); - } -} diff --git a/rust/tests/diamond_creation_test/Cargo.lock b/rust/tests/diamond_creation_test/Cargo.lock deleted file mode 100644 index 189052b1..00000000 --- a/rust/tests/diamond_creation_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/diamond_creation_test/Cargo.toml b/rust/tests/diamond_creation_test/Cargo.toml deleted file mode 100644 index 705e4781..00000000 --- a/rust/tests/diamond_creation_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "diamond_creation_test" -version = "0.1.0" -authors = ["MSilva95 "] -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"} diff --git a/rust/tests/diamond_creation_test/src/main.rs b/rust/tests/diamond_creation_test/src/main.rs deleted file mode 100644 index 35b293d6..00000000 --- a/rust/tests/diamond_creation_test/src/main.rs +++ /dev/null @@ -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 ", - ] - ); - } -} diff --git a/rust/tests/division_and_remainder_test/Cargo.lock b/rust/tests/division_and_remainder_test/Cargo.lock deleted file mode 100644 index 853701d6..00000000 --- a/rust/tests/division_and_remainder_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/division_and_remainder_test/Cargo.toml b/rust/tests/division_and_remainder_test/Cargo.toml deleted file mode 100644 index 8785f0c8..00000000 --- a/rust/tests/division_and_remainder_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "division_and_remainder_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -division_and_remainder= { path = "../../../../rust-piscine-solutions/division_and_remainder" } diff --git a/rust/tests/division_and_remainder_test/src/main.rs b/rust/tests/division_and_remainder_test/src/main.rs deleted file mode 100644 index d07f1811..00000000 --- a/rust/tests/division_and_remainder_test/src/main.rs +++ /dev/null @@ -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); -} diff --git a/rust/tests/doubtful_test/Cargo.lock b/rust/tests/doubtful_test/Cargo.lock deleted file mode 100644 index 161913ec..00000000 --- a/rust/tests/doubtful_test/Cargo.lock +++ /dev/null @@ -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" diff --git a/rust/tests/doubtful_test/Cargo.toml b/rust/tests/doubtful_test/Cargo.toml deleted file mode 100644 index 2b679622..00000000 --- a/rust/tests/doubtful_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "doubtful_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -doubtful = { path = "../../../../rust-piscine-solutions/doubtful" } \ No newline at end of file diff --git a/rust/tests/doubtful_test/src/main.rs b/rust/tests/doubtful_test/src/main.rs deleted file mode 100644 index 487aa671..00000000 --- a/rust/tests/doubtful_test/src/main.rs +++ /dev/null @@ -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 + "?"); -} diff --git a/rust/tests/drop_the_thread_test/Cargo.lock b/rust/tests/drop_the_thread_test/Cargo.lock deleted file mode 100644 index 2bd03a8e..00000000 --- a/rust/tests/drop_the_thread_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/drop_the_thread_test/Cargo.toml b/rust/tests/drop_the_thread_test/Cargo.toml deleted file mode 100644 index 875b1907..00000000 --- a/rust/tests/drop_the_thread_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "drop_the_thread_test" -version = "0.1.0" -authors = ["lee "] -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"} diff --git a/rust/tests/drop_the_thread_test/src/main.rs b/rust/tests/drop_the_thread_test/src/main.rs deleted file mode 100644 index f2882549..00000000 --- a/rust/tests/drop_the_thread_test/src/main.rs +++ /dev/null @@ -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(); - } -} diff --git a/rust/tests/edit_distance_test/Cargo.lock b/rust/tests/edit_distance_test/Cargo.lock deleted file mode 100644 index 66ca318d..00000000 --- a/rust/tests/edit_distance_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/edit_distance_test/Cargo.toml b/rust/tests/edit_distance_test/Cargo.toml deleted file mode 100644 index 4d034666..00000000 --- a/rust/tests/edit_distance_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "edit_distance_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -edit_distance = { path = "../../../../rust-piscine-solutions/edit_distance"} \ No newline at end of file diff --git a/rust/tests/edit_distance_test/src/main.rs b/rust/tests/edit_distance_test/src/main.rs deleted file mode 100644 index 2ba866c3..00000000 --- a/rust/tests/edit_distance_test/src/main.rs +++ /dev/null @@ -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::>(); -// let tar = target.chars().collect::>(); -// 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); - } -} diff --git a/rust/tests/error_type_test/Cargo.lock b/rust/tests/error_type_test/Cargo.lock deleted file mode 100644 index 21a3eb4f..00000000 --- a/rust/tests/error_type_test/Cargo.lock +++ /dev/null @@ -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" diff --git a/rust/tests/error_type_test/Cargo.toml b/rust/tests/error_type_test/Cargo.toml deleted file mode 100644 index dd5627fa..00000000 --- a/rust/tests/error_type_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "error_type_test" -version = "0.1.0" -authors = ["lee "] -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"} diff --git a/rust/tests/error_type_test/src/main.rs b/rust/tests/error_type_test/src/main.rs deleted file mode 100644 index 6685e5a2..00000000 --- a/rust/tests/error_type_test/src/main.rs +++ /dev/null @@ -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, FErr> - } - - impl <'a> TestForm<'_> { - // all test cases - fn new() -> Vec> { - 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); - } - } -} \ No newline at end of file diff --git a/rust/tests/events_test/Cargo.lock b/rust/tests/events_test/Cargo.lock deleted file mode 100644 index 01eb47d0..00000000 --- a/rust/tests/events_test/Cargo.lock +++ /dev/null @@ -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" diff --git a/rust/tests/events_test/Cargo.toml b/rust/tests/events_test/Cargo.toml deleted file mode 100644 index 958cd033..00000000 --- a/rust/tests/events_test/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "events_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -chrono = "0.4" -colored = "2" -events = { path = "../../../../rust-piscine-solutions/events"} \ No newline at end of file diff --git a/rust/tests/events_test/src/main.rs b/rust/tests/events_test/src/main.rs deleted file mode 100644 index f5f5e0e0..00000000 --- a/rust/tests/events_test/src/main.rs +++ /dev/null @@ -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"), - } - ); - } -} diff --git a/rust/tests/fibonacci2_test/Cargo.lock b/rust/tests/fibonacci2_test/Cargo.lock deleted file mode 100644 index e135144b..00000000 --- a/rust/tests/fibonacci2_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/fibonacci2_test/Cargo.toml b/rust/tests/fibonacci2_test/Cargo.toml deleted file mode 100644 index 1304f43c..00000000 --- a/rust/tests/fibonacci2_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "fibonacci2_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -fibonacci2 = {path = "../../../../rust-piscine-solutions/fibonacci2"} diff --git a/rust/tests/fibonacci2_test/src/main.rs b/rust/tests/fibonacci2_test/src/main.rs deleted file mode 100644 index 4b3e0cc1..00000000 --- a/rust/tests/fibonacci2_test/src/main.rs +++ /dev/null @@ -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); -} diff --git a/rust/tests/find_factorial_test/Cargo.lock b/rust/tests/find_factorial_test/Cargo.lock deleted file mode 100644 index f8022035..00000000 --- a/rust/tests/find_factorial_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/find_factorial_test/Cargo.toml b/rust/tests/find_factorial_test/Cargo.toml deleted file mode 100644 index 93a57a2f..00000000 --- a/rust/tests/find_factorial_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "find_factorial_test" -version = "0.1.0" -authors = ["MSilva95 "] -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"} diff --git a/rust/tests/find_factorial_test/src/main.rs b/rust/tests/find_factorial_test/src/main.rs deleted file mode 100644 index 73e50b1d..00000000 --- a/rust/tests/find_factorial_test/src/main.rs +++ /dev/null @@ -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)); - } -} diff --git a/rust/tests/generics_test/Cargo.lock b/rust/tests/generics_test/Cargo.lock deleted file mode 100644 index c5418bd2..00000000 --- a/rust/tests/generics_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/generics_test/Cargo.toml b/rust/tests/generics_test/Cargo.toml deleted file mode 100644 index 7f767294..00000000 --- a/rust/tests/generics_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "generics_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -generics = { path = "../../../../rust-piscine-solutions/generics"} \ No newline at end of file diff --git a/rust/tests/generics_test/src/main.rs b/rust/tests/generics_test/src/main.rs deleted file mode 100644 index f95b0023..00000000 --- a/rust/tests/generics_test/src/main.rs +++ /dev/null @@ -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); -} diff --git a/rust/tests/get_products_test/Cargo.lock b/rust/tests/get_products_test/Cargo.lock deleted file mode 100644 index d26d0b66..00000000 --- a/rust/tests/get_products_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/get_products_test/Cargo.toml b/rust/tests/get_products_test/Cargo.toml deleted file mode 100644 index b847ada0..00000000 --- a/rust/tests/get_products_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "get_products_test" -version = "0.1.0" -authors = ["MSilva95 "] -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"} diff --git a/rust/tests/get_products_test/src/main.rs b/rust/tests/get_products_test/src/main.rs deleted file mode 100644 index 2917b01b..00000000 --- a/rust/tests/get_products_test/src/main.rs +++ /dev/null @@ -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 = 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 = vec![1, 7, 3, 4]; - let output = get_products(arr); - let arr2: Vec = 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 = Vec::new(); - let output = get_products(arr); - assert_eq!(output, vec![]); - } - - #[test] - fn test_single_case() { - let arr: Vec = vec![2]; - let output = get_products(arr); - assert_eq!(output, vec![]); - } -} diff --git a/rust/tests/groceries_test/Cargo.lock b/rust/tests/groceries_test/Cargo.lock deleted file mode 100644 index e0206feb..00000000 --- a/rust/tests/groceries_test/Cargo.lock +++ /dev/null @@ -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", -] diff --git a/rust/tests/groceries_test/Cargo.toml b/rust/tests/groceries_test/Cargo.toml deleted file mode 100644 index c472d1d8..00000000 --- a/rust/tests/groceries_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "groceries_test" -version = "0.1.0" -authors = ["MSilva95 "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -groceries = { path = "../../../../rust-piscine-solutions/groceries" } diff --git a/rust/tests/groceries_test/src/main.rs b/rust/tests/groceries_test/src/main.rs deleted file mode 100644 index ba035f16..00000000 --- a/rust/tests/groceries_test/src/main.rs +++ /dev/null @@ -1,43 +0,0 @@ -// # Instructions - -// Create a function called `insert` -// fn insert(vec: &mut Vec, val: String) that inserts a new element at the end of the Vec - -#[allow(unused_imports)] -use groceries::*; - -#[allow(dead_code)] -fn main() { - let mut groceries = vec![ - "yogurt".to_string(), - "panetone".to_string(), - "bread".to_string(), - "cheese".to_string(), - ]; - insert(&mut groceries, String::from("nuts")); - println!("The groceries list now = {:?}", &groceries); - println!( - "The second element of the grocery list is {:?}", - at_index(&groceries, 1) - ); -} - -#[test] -fn test_insertions() { - let mut groceries = Vec::new(); - insert(&mut groceries, "milk".to_string()); - assert_eq!(groceries, ["milk"]); - insert(&mut groceries, "bread".to_string()); - assert_eq!(groceries, ["milk", "bread"]); -} - -#[test] -fn test_index() { - let groceries: Vec = vec![ - "milk".to_string(), - "bread".to_string(), - "water".to_string(), - "wine".to_string(), - ]; - assert_eq!(at_index(&groceries, 0), "milk"); -} diff --git a/rust/tests/handling_test/Cargo.lock b/rust/tests/handling_test/Cargo.lock deleted file mode 100644 index a780a192..00000000 --- a/rust/tests/handling_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "handling" -version = "0.1.0" - -[[package]] -name = "handling_test" -version = "0.1.0" -dependencies = [ - "handling", -] diff --git a/rust/tests/handling_test/Cargo.toml b/rust/tests/handling_test/Cargo.toml deleted file mode 100644 index 0e66dff7..00000000 --- a/rust/tests/handling_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "handling_test" -version = "0.1.0" -authors = ["lee "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -handling = { path = "../../../../rust-piscine-solutions/handling"} diff --git a/rust/tests/handling_test/a.txt b/rust/tests/handling_test/a.txt deleted file mode 100644 index 7dde7fad..00000000 --- a/rust/tests/handling_test/a.txt +++ /dev/null @@ -1 +0,0 @@ -content to be written \ No newline at end of file diff --git a/rust/tests/handling_test/src/main.rs b/rust/tests/handling_test/src/main.rs deleted file mode 100644 index e8c66fec..00000000 --- a/rust/tests/handling_test/src/main.rs +++ /dev/null @@ -1,63 +0,0 @@ -use std::fs::{File, OpenOptions}; -use std::io::prelude::*; -use std::io::{ErrorKind, Write}; -use handling::*; - -fn main() { - let path = "a.txt"; - File::create(path).unwrap(); - open_or_create(path, "content to be written"); - - let mut file = File::open(path).unwrap(); - - let mut s = String::new(); - file.read_to_string(&mut s).unwrap(); - println!("{}", s); - // output: content to be written -} - -#[cfg(test)] -mod tests { - use super::*; - use std::fs; - use std::panic; - - fn get_file_content(filename: &str) -> String { - let mut file = File::open(filename).unwrap(); - let mut s = String::new(); - file.read_to_string(&mut s).unwrap(); - fs::remove_file(filename).unwrap(); - return s; - } - - #[test] - fn test_if_file_exists() { - let filename = "test_existing_file.txt"; - let content = "hello world!"; - File::create(filename).unwrap(); - open_or_create(filename, content); - - assert_eq!(content, get_file_content(filename)); - } - - #[test] - fn test_create_file() { - let file = "no_existing_file.txt"; - let content = "hello world!"; - open_or_create(file, content); - - assert_eq!(content, get_file_content(file)); - } - #[test] - fn test_error_case() { - let filename = "hello.txt"; - File::create(filename).unwrap(); - let mut perms = fs::metadata(filename).unwrap().permissions(); - perms.set_readonly(true); - fs::set_permissions(filename, perms).unwrap(); - - let result = panic::catch_unwind(|| open_or_create(filename, "test")); - fs::remove_file(filename).unwrap(); - assert!(result.is_err()); - } -} diff --git a/rust/tests/hashing_test/Cargo.lock b/rust/tests/hashing_test/Cargo.lock deleted file mode 100644 index a6e75223..00000000 --- a/rust/tests/hashing_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "hashing" -version = "0.1.0" - -[[package]] -name = "hashing_test" -version = "0.1.0" -dependencies = [ - "hashing", -] diff --git a/rust/tests/hashing_test/Cargo.toml b/rust/tests/hashing_test/Cargo.toml deleted file mode 100644 index 51918cdc..00000000 --- a/rust/tests/hashing_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "hashing_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -hashing = { path = "../../../../rust-piscine-solutions/hashing"} diff --git a/rust/tests/hashing_test/src/main.rs b/rust/tests/hashing_test/src/main.rs deleted file mode 100644 index a9ddab99..00000000 --- a/rust/tests/hashing_test/src/main.rs +++ /dev/null @@ -1,41 +0,0 @@ -// Given a list of integers (Vec) write three functions -// Write a function called `mean` that calculates the `mean` (the average value) of all the values in the list -// Write a function called `median` that calculates the `median` (for a sorted list is the value in the middle) -// Write a function called `mode` that calculates the mode (the value -// that appears more often) - -use hashing::*; - -#[allow(dead_code)] -fn main() { - println!("Hello, world!"); - let v = vec![4, 7, 5, 2, 5, 1, 3]; - println!("mean {}", mean(&v)); - println!("median {}", median(&v)); - println!("mode {}", mode(&v)); -} - -use std::f64; - -#[allow(dead_code)] -fn approx_eq(a: f64, b: f64) -> bool { - (a - b).abs() < f64::EPSILON -} - -#[test] -fn test_mean() { - let v = vec![4, 7, 5, 2, 5, 1, 3]; - assert!(approx_eq(mean(&v), 3.857142857142857)); -} - -#[test] -fn test_median() { - let v = vec![4, 7, 5, 2, 5, 1, 3]; - assert_eq!(median(&v), 4); -} - -#[test] -fn test_mode() { - let v = vec![4, 7, 5, 2, 5, 1, 3]; - assert_eq!(mode(&v), 5); -} diff --git a/rust/tests/highest_test/Cargo.lock b/rust/tests/highest_test/Cargo.lock deleted file mode 100644 index fe19516b..00000000 --- a/rust/tests/highest_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "highest" -version = "0.1.0" - -[[package]] -name = "highest_test" -version = "0.1.0" -dependencies = [ - "highest", -] diff --git a/rust/tests/highest_test/Cargo.toml b/rust/tests/highest_test/Cargo.toml deleted file mode 100644 index e05f0d88..00000000 --- a/rust/tests/highest_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "highest_test" -version = "0.1.0" -authors = ["MSilva95 "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -highest = { path = "../../../../rust-piscine-solutions/highest"} diff --git a/rust/tests/highest_test/src/main.rs b/rust/tests/highest_test/src/main.rs deleted file mode 100644 index 45ab3cfd..00000000 --- a/rust/tests/highest_test/src/main.rs +++ /dev/null @@ -1,72 +0,0 @@ -/* -## Highest - -### Instructions - - In this exercise you will be given a `Numbers` struct. - Your task is to write these methods: - `List` that returns an `array` with every number in the struct - `Latest` that returns an `Option` with the last added number - `Highest` that return an `Option` with the highest number from the list, - `Highest_Three` that returns a `Vec` with the three highest numbers. - - ### Notions - -- https://doc.rust-lang.org/book/ch13-02-iterators.html - -*/ -use highest::*; - -fn main() { - let expected = [30, 500, 20, 70]; - let n = Numbers::new(&expected); - println!("{:?}", n.List()); - - println!("{:?}", n.Highest()); - println!("{:?}", n.Latest()); - println!("{:?}", n.Highest_Three()); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_List() { - let expected = [30, 50, 20, 70]; - let n = Numbers::new(&expected); - assert_eq!(n.List(), &expected); - } - - #[test] - fn test_Latest() { - let n = Numbers::new(&[100, 0, 90, 30]); - let f = Numbers::new(&[]); - assert_eq!(n.Latest(), Some(30)); - assert!(f.Latest().is_none(), "It should have been None, {:?}", f.Latest()); - } - - #[test] - fn test_Highest() { - let n = Numbers::new(&[40, 100, 70]); - let f = Numbers::new(&[]); - assert_eq!(n.Highest(), Some(100)); - assert!(f.Highest().is_none(), "It should have been None, {:?}", f.Highest()); - } - - #[test] - fn test_Highest_Three() { - let e = Numbers::new(&[10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70]); - let f = Numbers::new(&[40, 20, 40, 30]); - let g = Numbers::new(&[30, 70]); - let h = Numbers::new(&[40]); - let i = Numbers::new(&[]); - let j = Numbers::new(&[20, 10, 30]); - assert_eq!(e.Highest_Three(), vec![100, 90, 70]); - assert_eq!(f.Highest_Three(), vec![40, 40, 30]); - assert_eq!(g.Highest_Three(), vec![70, 30]); - assert_eq!(h.Highest_Three(), vec![40]); - assert!(i.Highest_Three().is_empty()); - assert_eq!(j.Highest_Three(), vec![30, 20, 10]); - } -} diff --git a/rust/tests/how_many_references_test/Cargo.lock b/rust/tests/how_many_references_test/Cargo.lock deleted file mode 100644 index a7356cd1..00000000 --- a/rust/tests/how_many_references_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "how_many_references" -version = "0.1.0" - -[[package]] -name = "how_many_references_test" -version = "0.1.0" -dependencies = [ - "how_many_references", -] diff --git a/rust/tests/how_many_references_test/Cargo.toml b/rust/tests/how_many_references_test/Cargo.toml deleted file mode 100644 index e2a00417..00000000 --- a/rust/tests/how_many_references_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "how_many_references_test" -version = "0.1.0" -authors = ["lee "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -how_many_references = { path = "../../../../rust-piscine-solutions/how_many_references"} diff --git a/rust/tests/how_many_references_test/src/main.rs b/rust/tests/how_many_references_test/src/main.rs deleted file mode 100644 index 7ccbddad..00000000 --- a/rust/tests/how_many_references_test/src/main.rs +++ /dev/null @@ -1,103 +0,0 @@ -use how_many_references::*; - -fn main() { - let a = Rc::new(String::from("a")); - let b = Rc::new(String::from("b")); - let c = Rc::new(String::from("c")); - - let a1 = Rc::new(String::from("a")); - - let mut new_node = Node::new(vec![a.clone()]); - new_node.add_ele(b.clone()); - new_node.add_ele(a.clone()); - new_node.add_ele(c.clone()); - new_node.add_ele(a.clone()); - - println!("a: {:?}", how_many_references(&a)); - println!("b: {:?}", how_many_references(&b)); - println!("c: {:?}", how_many_references(&c)); - new_node.rm_all_ref(a1.clone()); - new_node.rm_all_ref(a.clone()); - - println!("a: {:?}", how_many_references(&a)); - println!("b: {:?}", how_many_references(&b)); - println!("c: {:?}", how_many_references(&c)); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_add_ele() { - let a = Rc::new(String::from("a")); - let b = Rc::new(String::from("b")); - let c = Rc::new(String::from("c")); - - let mut new_node = Node::new(vec![a.clone()]); - new_node.add_ele(a.clone()); - new_node.add_ele(b.clone()); - new_node.add_ele(c.clone()); - - assert_eq!(new_node.value, vec![a.clone(), a, b, c]); - } - #[test] - fn test_how_many_references() { - let a = Rc::new(String::from("a")); - let b = Rc::new(String::from("b")); - let c = Rc::new(String::from("c")); - let d = Rc::new(String::from("d")); - let mut new_node = Node::new(vec![]); - new_node.add_ele(b.clone()); - new_node.add_ele(a.clone()); - new_node.add_ele(c.clone()); - new_node.add_ele(a.clone()); - - assert_eq!(how_many_references(&d), 1); - assert_eq!(how_many_references(&a), 3); - assert_eq!(how_many_references(&b), 2); - assert_eq!(how_many_references(&c), 2); - } - - #[test] - fn test_rm_all_ref() { - let a = Rc::new(String::from("a")); - let b = Rc::new(String::from("b")); - let c = Rc::new(String::from("c")); - let d = Rc::new(String::from("d")); - - let a1 = Rc::new(String::from("a")); - let b1 = Rc::new(String::from("b")); - let c1 = Rc::new(String::from("c")); - let d1 = Rc::new(String::from("d")); - let mut new_node = Node::new(vec![ - d.clone(), - d.clone(), - b.clone(), - a.clone(), - c.clone(), - a.clone(), - d.clone(), - ]); - - new_node.rm_all_ref(a1.clone()); - assert_eq!(how_many_references(&a), 3); - new_node.rm_all_ref(a.clone()); - assert_eq!(how_many_references(&a), 1); - - new_node.rm_all_ref(b1.clone()); - assert_eq!(how_many_references(&b), 2); - new_node.rm_all_ref(b.clone()); - assert_eq!(how_many_references(&b), 1); - - new_node.rm_all_ref(c1.clone()); - assert_eq!(how_many_references(&c), 2); - new_node.rm_all_ref(c.clone()); - assert_eq!(how_many_references(&c), 1); - - new_node.rm_all_ref(d1.clone()); - assert_eq!(how_many_references(&d), 4); - new_node.rm_all_ref(d.clone()); - assert_eq!(how_many_references(&d), 1); - } -} diff --git a/rust/tests/iterators_test/Cargo.lock b/rust/tests/iterators_test/Cargo.lock deleted file mode 100644 index 5451fbfe..00000000 --- a/rust/tests/iterators_test/Cargo.lock +++ /dev/null @@ -1,13 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "iterators" -version = "0.1.0" - -[[package]] -name = "iterators_test" -version = "0.1.0" -dependencies = [ - "iterators 0.1.0", -] - diff --git a/rust/tests/iterators_test/Cargo.toml b/rust/tests/iterators_test/Cargo.toml deleted file mode 100644 index dd7616c5..00000000 --- a/rust/tests/iterators_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "iterators_test" -version = "0.1.0" -authors = ["MSilva95 "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -iterators = { path = "../../../../rust-piscine-solutions/iterators"} diff --git a/rust/tests/iterators_test/src/main.rs b/rust/tests/iterators_test/src/main.rs deleted file mode 100644 index 9983ca5b..00000000 --- a/rust/tests/iterators_test/src/main.rs +++ /dev/null @@ -1,62 +0,0 @@ -/* -## iterators - -### Instructions - -Create a method `new` that takes one number `usize` and initializes the `Number` struct. -This method will have to determinate if the given number is even or odd, -if it is even you will have to increment one to the odd number and -if it is odd you have to increment one to the even number. - -After that you will implement an iterator for the struct `Number` that returns a tuple (usize,usize,usize). -containing each field of the struct Number. -The first position of the tuple will be the even numbers, -the second will be the odd numbers, -and the third will be the factorial numbers. - -### Notions - -- https://doc.rust-lang.org/std/iter/trait.Iterator.html - -*/ -use iterators::*; - -fn main() { - let mut a = Number::new(5); - println!("{:?}", a.next()); // Some((6, 5, 120)) - println!("{:?}", a.next()); // Some((8, 7, 720)) - println!("{:?}", a.next()); // Some((10, 9, 5040)) - println!(); - let mut a = Number::new(18); - println!("{:?}", a.next()); // Some((18, 19, 6402373705728000)) - println!("{:?}", a.next()); // Some((20, 21, 121645100408832000)) - println!("{:?}", a.next()); // Some((22, 23, 2432902008176640000)) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_first_seven() { - let test_even = vec![0, 2, 4, 6, 8, 10, 12]; - let test_odd = vec![1, 3, 5, 7, 9, 11, 13]; - let test_fact = vec![1, 1, 2, 6, 24, 120, 720]; - - for (i, x) in Number::new(0).take(7).enumerate() { - assert_eq!(x.0, test_even[i]); - assert_eq!(x.1, test_odd[i]); - assert_eq!(x.2, test_fact[i]); - } - } - - #[test] - fn test_next() { - let mut a = Number::new(6); - assert_eq!(a.next().unwrap(), (6, 7, 720)); - assert_eq!(a.next().unwrap(), (8, 9, 5040)); - assert_eq!(a.next().unwrap(), (10, 11, 40320)); - assert_eq!(a.next().unwrap(), (12, 13, 362880)); - assert_eq!(a.next().unwrap(), (14, 15, 3628800)); - } -} diff --git a/rust/tests/lalgebra_scalar_test/Cargo.lock b/rust/tests/lalgebra_scalar_test/Cargo.lock deleted file mode 100644 index c114e7a3..00000000 --- a/rust/tests/lalgebra_scalar_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "lalgebra_scalar" -version = "0.1.0" - -[[package]] -name = "lalgebra_scalar_test" -version = "0.1.0" -dependencies = [ - "lalgebra_scalar", -] diff --git a/rust/tests/lalgebra_scalar_test/Cargo.toml b/rust/tests/lalgebra_scalar_test/Cargo.toml deleted file mode 100644 index c94f3ae7..00000000 --- a/rust/tests/lalgebra_scalar_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "lalgebra_scalar_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -lalgebra_scalar = { path = "../../../../rust-piscine-solutions/lalgebra_scalar"} \ No newline at end of file diff --git a/rust/tests/lalgebra_scalar_test/src/main.rs b/rust/tests/lalgebra_scalar_test/src/main.rs deleted file mode 100644 index 93492f97..00000000 --- a/rust/tests/lalgebra_scalar_test/src/main.rs +++ /dev/null @@ -1,73 +0,0 @@ -// # Instructions -// A scalar type must implement the operations -// Addition, Subtraction, Multiplication and Division (you might -// also have to use more restrictions). For this use a trait -// inheritance (supertraits) - -// Another condition for a number to be a scalar is to have a zero -// (neutral element in the addition) and a one (neutral element in the -// multiplication). Therefore the Scalar trait will require 2 -// functions zero() and one() - -// After finishing implement the Scalar trait for u32, u64, i32, i64, -// f32, f64 - -use lalgebra_scalar::Scalar; - -#[allow(dead_code)] -fn main() { - println!("{:?}", f64::zero()); - println!("{:?}", i32::zero()); -} - -#[test] -fn scalar_u32() { - let a: u32 = u32::zero(); - assert_eq!(a, 0 as u32); - - let b = u32::one(); - assert_eq!(b, 1 as u32); -} - -#[test] -fn scalar_u64() { - let a = u64::zero(); - assert_eq!(a, 0 as u64); - - let b = u64::one(); - assert_eq!(b, 1 as u64); -} - -#[test] -fn scalar_i32() { - let a: i32 = i32::zero(); - assert_eq!(a, 0 as i32); - - let b = i32::one(); - assert_eq!(b, 1 as i32); -} - -#[test] -fn scalar_i64() { - let a: i64 = i64::zero(); - assert_eq!(a, 0 as i64); - - let b = i64::one(); - assert_eq!(b, 1 as i64); -} - -#[test] -fn scalar_f32() { - let zero = f32::zero(); - assert_eq!(zero, 0.0); - let one = f32::one(); - assert_eq!(one, 1.0); -} - -#[test] -fn scalar_f64() { - let zero = f64::zero(); - assert_eq!(zero, 0.0); - let one = f64::one(); - assert_eq!(one, 1.0); -} diff --git a/rust/tests/lalgebra_vector_test/Cargo.lock b/rust/tests/lalgebra_vector_test/Cargo.lock deleted file mode 100644 index 99587775..00000000 --- a/rust/tests/lalgebra_vector_test/Cargo.lock +++ /dev/null @@ -1,19 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "lalgebra_scalar" -version = "0.1.0" - -[[package]] -name = "lalgebra_vector" -version = "0.1.0" -dependencies = [ - "lalgebra_scalar", -] - -[[package]] -name = "lalgebra_vector_test" -version = "0.1.0" -dependencies = [ - "lalgebra_vector", -] diff --git a/rust/tests/lalgebra_vector_test/Cargo.toml b/rust/tests/lalgebra_vector_test/Cargo.toml deleted file mode 100644 index 537e690e..00000000 --- a/rust/tests/lalgebra_vector_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "lalgebra_vector_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -lalgebra_vector = { path = "../../../../rust-piscine-solutions/lalgebra_vector"} \ No newline at end of file diff --git a/rust/tests/lalgebra_vector_test/src/main.rs b/rust/tests/lalgebra_vector_test/src/main.rs deleted file mode 100644 index 99761c75..00000000 --- a/rust/tests/lalgebra_vector_test/src/main.rs +++ /dev/null @@ -1,41 +0,0 @@ -// A vector in linear algebra is define as "anything that can be added -// and that can be multiplied by a scalar" -// And the associated function dot that calculates the dot product -// between two vectors -// let vector = Vector(vec![0,3, 4]); -// let vector_1 = Vector(vec![0,3,3]); -// vector.dot(&vector_1) == Some(23); - -// The dot product between two vectors of different length it's not defined - -use lalgebra_vector::Vector; - -fn main() { - let vector_1: Vector = Vector(vec![1, 3, -5]); - let vector_2: Vector = Vector(vec![4, -2, -1]); - println!("{:?}", vector_1.dot(&vector_2)); - println!("{:?}", vector_1 + &vector_2); -} - -#[test] -fn dot_product() { - let vector_1: Vector = Vector(vec![1, 3, -5]); - let vector_2: Vector = Vector(vec![4, -2, -1]); - let expected: i64 = 3; - assert_eq!(vector_1.dot(&vector_2), Some(expected)); - - let vector_1: Vector = Vector(vec![1, 3, -5]); - let vector_2: Vector = Vector(vec![4, -2]); - assert_eq!(vector_1.dot(&vector_2), None); -} - -#[test] -fn addition() { - let vector_1: Vector = Vector(vec![1, 3, -5]); - let vector_2: Vector = Vector(vec![4, -2, -1]); - assert_eq!(vector_1 + &vector_2, Some(Vector(vec![5i64, 1, -6]))); - - let vector_1: Vector = Vector(vec![1, 3, -5]); - let vector_2: Vector = Vector(vec![2, 4, -2, -1]); - assert_eq!(None, vector_1 + &vector_2); -} diff --git a/rust/tests/lifetimes_test/Cargo.lock b/rust/tests/lifetimes_test/Cargo.lock deleted file mode 100644 index a425a190..00000000 --- a/rust/tests/lifetimes_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "lifetimes" -version = "0.1.0" - -[[package]] -name = "lifetimes_test" -version = "0.1.0" -dependencies = [ - "lifetimes", -] diff --git a/rust/tests/lifetimes_test/Cargo.toml b/rust/tests/lifetimes_test/Cargo.toml deleted file mode 100644 index cfe2716e..00000000 --- a/rust/tests/lifetimes_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "lifetimes_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -lifetimes = { path = "../../../../rust-piscine-solutions/lifetimes"} diff --git a/rust/tests/lifetimes_test/src/main.rs b/rust/tests/lifetimes_test/src/main.rs deleted file mode 100644 index c970a98f..00000000 --- a/rust/tests/lifetimes_test/src/main.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Create a struct called Person that has two fields: name of type -// string slice (&str) and age of type u8 -// and create the associated function new which creates a new person -// with age 0 and with the name given - -use lifetimes::Person; - -fn main() { - let person = Person::new("Leo"); - - println!("Person = {:?}", person); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn fields() { - let person = Person { - name: "Dijkstra", - age: 10, - }; - assert_eq!(person.age, 10); - assert_eq!(person.name, "Dijkstra"); - } - - #[test] - fn create_person() { - let person = Person::new("Leo"); - assert_eq!(person.age, 0); - assert_eq!(person.name, "Leo"); - } -} diff --git a/rust/tests/logic_number_test/Cargo.lock b/rust/tests/logic_number_test/Cargo.lock deleted file mode 100644 index df352370..00000000 --- a/rust/tests/logic_number_test/Cargo.lock +++ /dev/null @@ -1,5 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "logic-number" -version = "0.1.0" diff --git a/rust/tests/logic_number_test/Cargo.toml b/rust/tests/logic_number_test/Cargo.toml deleted file mode 100644 index f4ea4533..00000000 --- a/rust/tests/logic_number_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "logic_number_test" -version = "0.1.0" -authors = ["MSilva95 "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -logic_number = { path = "../../../../rust-piscine-solutions/logic_number"} diff --git a/rust/tests/logic_number_test/src/main.rs b/rust/tests/logic_number_test/src/main.rs deleted file mode 100644 index 86396381..00000000 --- a/rust/tests/logic_number_test/src/main.rs +++ /dev/null @@ -1,65 +0,0 @@ -/* -## logic_number - -### Instructions - -In this exercise it will be given an example of a sequence of numbers, your purpose is to -determinate if the sequence returns true or false. -For this you have to create a function `number_logic` that will take a number `u32` and return true -if the number is the sum of its own digits, each raised to the power of the number of digits, -and false otherwise. - -### Example: - - 9 returns true, because 9 = 9^1 = 9 - 10 returns false, because 10 != 1^2 + 0^2 = 1 - 153 returns true, because: 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153 - 154 returns false, because: 154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190 -*/ -use logic_number::*; -fn main() { - let array = [9, 10, 153, 154]; - for pat in &array { - if number_logic(*pat) == true { - println!( - "this number returns {} because the number {} obey the rules of the sequence", - number_logic(*pat), - pat - ) - } - if number_logic(*pat) == false { - println!("this number returns {} because the number {} does not obey the rules of the sequence", number_logic(*pat),pat ) - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_zero() { - assert!(number_logic(0)) - } - - #[test] - fn test_single_digit_numbers() { - assert!(number_logic(5)); - assert!(number_logic(9)) - } - - #[test] - fn test_two_digit_numbers() { - assert!(!number_logic(10)) - } - - #[test] - fn test_three_or_more_digit_number() { - assert!(number_logic(153)); - assert!(!number_logic(100)); - assert!(number_logic(9474)); - assert!(!number_logic(9475)); - assert!(number_logic(9_926_315)); - assert!(!number_logic(9_926_316)) - } -} diff --git a/rust/tests/looping_test/Cargo.lock b/rust/tests/looping_test/Cargo.lock deleted file mode 100644 index ea520f91..00000000 --- a/rust/tests/looping_test/Cargo.lock +++ /dev/null @@ -1,593 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "addr2line" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c0929d69e78dd9bf5408269919fcbcaeb2e35e5d43e5815517cdc6a8e11a423" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" - -[[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 = "backtrace" -version = "0.3.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef5140344c85b01f9bbb4d4b7288a8aa4b3287ccef913a14bcc78a1063623598" -dependencies = [ - "addr2line", - "cfg-if 1.0.0", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" - -[[package]] -name = "bstr" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "473fc6b38233f9af7baa94fb5852dca389e3d95b8e21c8e3719301462c5d9faf" -dependencies = [ - "memchr", -] - -[[package]] -name = "cc" -version = "1.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" - -[[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 = "error-chain" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" -dependencies = [ - "backtrace", - "version_check", -] - -[[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 = "gimli" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce" - -[[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 = "looping_test" -version = "0.1.0" -dependencies = [ - "assert_fs", - "escargot", - "rexpect", -] - -[[package]] -name = "memchr" -version = "2.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" - -[[package]] -name = "miniz_oxide" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d" -dependencies = [ - "adler", - "autocfg", -] - -[[package]] -name = "nix" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c722bee1037d430d0f8e687bbdbf222f27cc6e4e68d5caf630857bb2b6dbdce" -dependencies = [ - "bitflags", - "cc", - "cfg-if 0.1.10", - "libc", - "void", -] - -[[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 = "object" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" - -[[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.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" -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 = "rexpect" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "862c0149d91461fab225ddd06a5af919913f5c57405ed4f27d2466d6cc877186" -dependencies = [ - "error-chain", - "nix", - "regex", - "tempfile", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" - -[[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.54" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44" -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 = "version_check" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" - -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" - -[[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" diff --git a/rust/tests/looping_test/Cargo.toml b/rust/tests/looping_test/Cargo.toml deleted file mode 100644 index e74a0c19..00000000 --- a/rust/tests/looping_test/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "looping_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -escargot = "0.5" -assert_fs = "1.0.0" -rexpect = "0.4.0" \ No newline at end of file diff --git a/rust/tests/looping_test/src/main.rs b/rust/tests/looping_test/src/main.rs deleted file mode 100644 index a3a6b579..00000000 --- a/rust/tests/looping_test/src/main.rs +++ /dev/null @@ -1,51 +0,0 @@ -use rexpect::spawn; - -const MANIFEST_PATH: &str = "../../../../rust-piscine-solutions/looping/Cargo.toml"; - -#[test] -fn test_correct_answer() { - let riddle = "I am the beginning of the end, and the end of time and space. I am essential to creation, and I surround every place. What am I?"; - let temp = assert_fs::TempDir::new().unwrap(); - let _cmd = escargot::CargoBuild::new() - .bin("looping") - .current_release() - .current_target() - .manifest_path(MANIFEST_PATH) - .target_dir(temp.path()) - .run() - .unwrap(); - - let mut p = spawn(&_cmd.path().display().to_string(), Some(2000)).unwrap(); - p.exp_string(riddle).unwrap(); - p.send_line("The letter e").unwrap(); - p.exp_string("It took you 1 trials to get the right answer") - .unwrap(); -} - -#[test] -fn test_more_than_one_fail() { - let riddle = "I am the beginning of the end, and the end of time and space. I am essential to creation, and I surround every place. What am I?"; - - let temp = assert_fs::TempDir::new().unwrap(); - - let _cmd = escargot::CargoBuild::new() - .bin("looping") - .current_release() - .current_target() - .manifest_path(MANIFEST_PATH) - .target_dir(temp.path()) - .run() - .unwrap(); - - let mut p = spawn(&_cmd.path().display().to_string(), Some(2000)).unwrap(); - p.exp_string(riddle).unwrap(); - p.send_line("circle").unwrap(); - p.exp_string(riddle).unwrap(); - p.send_line("relativity").unwrap(); - p.exp_string(riddle).unwrap(); - p.send_line("the big bang").unwrap(); - p.exp_string(riddle).unwrap(); - p.send_line("The letter e").unwrap(); - p.exp_string("It took you 4 trials to get the right answer") - .unwrap(); -} diff --git a/rust/tests/matrix_mult_test/Cargo.lock b/rust/tests/matrix_mult_test/Cargo.lock deleted file mode 100644 index 7fb91365..00000000 --- a/rust/tests/matrix_mult_test/Cargo.lock +++ /dev/null @@ -1,19 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "lalgebra_scalar" -version = "0.1.0" - -[[package]] -name = "matrix" -version = "0.1.0" -dependencies = [ - "lalgebra_scalar", -] - -[[package]] -name = "matrix_test" -version = "0.1.0" -dependencies = [ - "matrix", -] diff --git a/rust/tests/matrix_mult_test/Cargo.toml b/rust/tests/matrix_mult_test/Cargo.toml deleted file mode 100644 index 9aba827c..00000000 --- a/rust/tests/matrix_mult_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "matrix_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -matrix = { path = "../../../../rust-piscine-solutions/matrix"} diff --git a/rust/tests/matrix_mult_test/src/main.rs b/rust/tests/matrix_mult_test/src/main.rs deleted file mode 100644 index a643a2e5..00000000 --- a/rust/tests/matrix_mult_test/src/main.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Now define the matrix multiplication by implementing the -// std::ops::Mul for the type matrix - -use matrix::Matrix; - -fn main() { - let matrix: Matrix = Matrix(vec![vec![3, 6], vec![8, 0]]); - println!("{:?}", matrix.col(0)); - println!("{:?}", matrix.row(1)); - - let matrix_1: Matrix = Matrix(vec![vec![0, 1], vec![0, 0]]); - let matrix_2: Matrix = Matrix(vec![vec![0, 0], vec![1, 0]]); - let mult = matrix_1.clone() * matrix_2.clone(); - println!("{:?}", mult); - println!("{:?}", matrix_1.number_of_cols()); - println!("{:?}", matrix_2.number_of_rows()); -} - -#[test] -fn get_row() { - let matrix: Matrix = Matrix(vec![vec![3, 6], vec![8, 0]]); - assert_eq!(vec![3u32, 6], matrix.row(0)); - assert_eq!(vec![8u32, 0], matrix.row(1)); -} - -#[test] -fn get_col() { - let matrix: Matrix = Matrix(vec![vec![3, 6], vec![8, 0]]); - assert_eq!(matrix.col(0), vec![3u32, 8]); - assert_eq!(vec![6u32, 0], matrix.col(1)); -} - -#[test] -fn matrix_multiplication() { - let matrix_1: Matrix = Matrix(vec![vec![0, 1], vec![0, 0]]); - let matrix_2: Matrix = Matrix(vec![vec![0, 0], vec![1, 0]]); - let expected: Matrix = Matrix(vec![vec![1, 0], vec![0, 0]]); - assert_eq!(matrix_1 * matrix_2, Some(expected)); - - let matrix_1: Matrix = Matrix(vec![vec![0, 1], vec![0, 0]]); - let matrix_2: Matrix = Matrix(vec![vec![0, 0, 0], vec![1, 0, 0], vec![1, 1, 1]]); - assert_eq!(matrix_1 * matrix_2, None); -} diff --git a/rust/tests/matrix_ops_test/Cargo.lock b/rust/tests/matrix_ops_test/Cargo.lock deleted file mode 100644 index 7fb91365..00000000 --- a/rust/tests/matrix_ops_test/Cargo.lock +++ /dev/null @@ -1,19 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "lalgebra_scalar" -version = "0.1.0" - -[[package]] -name = "matrix" -version = "0.1.0" -dependencies = [ - "lalgebra_scalar", -] - -[[package]] -name = "matrix_test" -version = "0.1.0" -dependencies = [ - "matrix", -] diff --git a/rust/tests/matrix_ops_test/Cargo.toml b/rust/tests/matrix_ops_test/Cargo.toml deleted file mode 100644 index 9aba827c..00000000 --- a/rust/tests/matrix_ops_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "matrix_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -matrix = { path = "../../../../rust-piscine-solutions/matrix"} diff --git a/rust/tests/matrix_ops_test/src/main.rs b/rust/tests/matrix_ops_test/src/main.rs deleted file mode 100644 index e291dbf3..00000000 --- a/rust/tests/matrix_ops_test/src/main.rs +++ /dev/null @@ -1,51 +0,0 @@ -// In this exercise you will define the basic operations with a matrix -// starting by implementing the `std::ops::Add` trait - -// Define the operation + (by defining the trait std::ops::Add) for -// two matrices remember that two matrices can only be added if they -// have the same size. Therefore the add method must handle the -// possibility of failure by returning an Option - -use matrix::Matrix; - -fn main() { - let matrix = Matrix(vec![vec![8, 1], vec![9, 1]]); - let matrix_2 = Matrix(vec![vec![1, 1], vec![1, 1]]); - println!("{:?}", matrix + matrix_2); - - let matrix = Matrix(vec![vec![1, 3], vec![2, 5]]); - let matrix_2 = Matrix(vec![vec![3, 1], vec![1, 1]]); - println!("{:?}", matrix - matrix_2); - - let matrix = Matrix(vec![vec![1, 1], vec![1, 1]]); - let matrix_2 = Matrix(vec![vec![1, 1, 3], vec![1, 1]]); - println!("{:?}", matrix - matrix_2); - - let matrix = Matrix(vec![vec![1, 3], vec![9, 1]]); - let matrix_2 = Matrix(vec![vec![1, 1, 3], vec![1, 1]]); - println!("{:?}", matrix + matrix_2); -} - -#[test] -fn addition() { - let matrix = Matrix(vec![vec![1, 1], vec![1, 1]]); - let matrix_2 = Matrix(vec![vec![1, 1], vec![1, 1]]); - let expected = Matrix(vec![vec![2, 2], vec![2, 2]]); - assert_eq!(matrix + matrix_2, Some(expected)); - - let matrix = Matrix(vec![vec![1, 1], vec![1, 1]]); - let matrix_2 = Matrix(vec![vec![1, 1, 3], vec![1, 1]]); - assert_eq!(matrix + matrix_2, None); -} - -#[test] -fn subtraction() { - let matrix = Matrix(vec![vec![1, 1], vec![1, 1]]); - let matrix_2 = Matrix(vec![vec![1, 1], vec![1, 1]]); - let expected = Matrix(vec![vec![0, 0], vec![0, 0]]); - assert_eq!(matrix - matrix_2, Some(expected)); - - let matrix = Matrix(vec![vec![1, 1], vec![1, 1]]); - let matrix_2 = Matrix(vec![vec![1, 1, 3], vec![1, 1]]); - assert_eq!(matrix - matrix_2, None); -} diff --git a/rust/tests/matrix_test/Cargo.lock b/rust/tests/matrix_test/Cargo.lock deleted file mode 100644 index 7fb91365..00000000 --- a/rust/tests/matrix_test/Cargo.lock +++ /dev/null @@ -1,19 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "lalgebra_scalar" -version = "0.1.0" - -[[package]] -name = "matrix" -version = "0.1.0" -dependencies = [ - "lalgebra_scalar", -] - -[[package]] -name = "matrix_test" -version = "0.1.0" -dependencies = [ - "matrix", -] diff --git a/rust/tests/matrix_test/Cargo.toml b/rust/tests/matrix_test/Cargo.toml deleted file mode 100644 index 9aba827c..00000000 --- a/rust/tests/matrix_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "matrix_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -matrix = { path = "../../../../rust-piscine-solutions/matrix"} diff --git a/rust/tests/matrix_test/src/main.rs b/rust/tests/matrix_test/src/main.rs deleted file mode 100644 index a8a006af..00000000 --- a/rust/tests/matrix_test/src/main.rs +++ /dev/null @@ -1,55 +0,0 @@ -// First exercise - -// # Instructions -// Define a data structure to represent a matrix of any size and -// implement the basic operations for this you will need to follow the -// next steps: - -// You can use a 2 dimensional Vec's -// We will consider a matrix as a rectangular arrangements of scalars -// You can use the definition of scalars done in the last exercise: -// `lalgebra_scalar` - -// Then define the associated function `identity` that returns the identity matrix -// of size n -// Ex: -// Matrix::identity(3) == [[1,0,0], [0,1,0], [0,0,1]] - -// And the associated function `zero` that returns a matrix of size -// `row x col` with all the positions filled by zeroes -// Ex: -// Matrix::zero(3, 3) == [[0,0,0],[0,0,0],[0,0,0]] - -// Resources: https://doc.rust-lang.org/book/ch19-03-advanced-traits.html - -use matrix::Matrix; - -#[allow(dead_code)] -fn main() { - let m: Matrix = Matrix(vec![vec![0, 0, 0, 0], vec![0, 0, 0, 0], vec![0, 0, 0, 0]]); - println!("{:?}", m); - println!("{:?}", Matrix::::identity(4)); - println!("{:?}", Matrix::::zero(3, 4)); -} - -#[test] -fn zero_property() { - let matrix: Matrix = Matrix::zero(3, 4); - let expected: Matrix = Matrix(vec![vec![0, 0, 0, 0], vec![0, 0, 0, 0], vec![0, 0, 0, 0]]); - assert_eq!(matrix, expected); - - let matrix: Matrix = Matrix::zero(2, 2); - let expected: Matrix = Matrix(vec![vec![0, 0], vec![0, 0]]); - assert_eq!(matrix, expected); -} - -#[test] -fn identy_matrix() { - let matrix: Matrix = Matrix::identity(2); - let expected: Matrix = Matrix(vec![vec![1, 0], vec![0, 1]]); - assert_eq!(matrix, expected); - - let matrix: Matrix = Matrix::identity(3); - let expected: Matrix = Matrix(vec![vec![1, 0, 0], vec![0, 1, 0], vec![0, 0, 1]]); - assert_eq!(matrix, expected); -} diff --git a/rust/tests/matrix_transposition_test/Cargo.lock b/rust/tests/matrix_transposition_test/Cargo.lock deleted file mode 100644 index 72bf41f3..00000000 --- a/rust/tests/matrix_transposition_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "matrix_transposition" -version = "0.1.0" - -[[package]] -name = "matrix_transposition_test" -version = "0.1.0" -dependencies = [ - "matrix_transposition", -] diff --git a/rust/tests/matrix_transposition_test/Cargo.toml b/rust/tests/matrix_transposition_test/Cargo.toml deleted file mode 100644 index 683e9909..00000000 --- a/rust/tests/matrix_transposition_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "matrix_transposition_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -matrix_transposition = { path = "../../../../rust-piscine-solutions/matrix_transposition"} diff --git a/rust/tests/matrix_transposition_test/src/main.rs b/rust/tests/matrix_transposition_test/src/main.rs deleted file mode 100644 index 2fcbfcf5..00000000 --- a/rust/tests/matrix_transposition_test/src/main.rs +++ /dev/null @@ -1,39 +0,0 @@ -use matrix_transposition::{transpose, Matrix}; - -fn main() { - let matrix = Matrix((1, 3), (4, 5)); - println!("Original matrix {:?}", matrix); - println!("Transpose matrix {:?}", transpose(matrix)); -} - -// #[derive(Debug)] -// struct Matrix((i32, i32), (i32, i32)); - -// fn transpose(m: Matrix) -> Matrix { -// Matrix(((m.0).0, (m.1).0), ((m.0).1, (m.1).1)) -// } - -#[test] -fn transpose_zero() { - let m = Matrix((0, 0), (0, 0)); - let m = transpose(m); - assert_eq!(m, Matrix((0, 0), (0, 0))); -} - -#[test] -fn transpose_identity() { - let m = Matrix((1, 0), (0, 1)); - let m = transpose(m); - assert_eq!(m, Matrix((1, 0), (0, 1))); -} - -#[test] -fn transpose_matrix() { - let m = Matrix((1, 3), (4, 5)); - let m = transpose(m); - assert_eq!(m, Matrix((1, 4), (3, 5))); - - let m = Matrix((6, 8), (1, 3)); - let m = transpose(m); - assert_eq!(m, Matrix((6, 1), (8, 3))); -} diff --git a/rust/tests/name_initials_test/Cargo.lock b/rust/tests/name_initials_test/Cargo.lock deleted file mode 100644 index 75c4b369..00000000 --- a/rust/tests/name_initials_test/Cargo.lock +++ /dev/null @@ -1,93 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[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 = "name_initials" -version = "0.1.0" -dependencies = [ - "jemalloc-ctl", - "jemallocator", -] - -[[package]] -name = "name_initials_test" -version = "0.1.0" -dependencies = [ - "jemalloc-ctl", - "jemallocator", - "name_initials", -] - -[[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" diff --git a/rust/tests/name_initials_test/Cargo.toml b/rust/tests/name_initials_test/Cargo.toml deleted file mode 100644 index 4f40145b..00000000 --- a/rust/tests/name_initials_test/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "name_initials_test" -version = "0.1.0" -authors = ["lee "] -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" -name_initials = { path = "../../../../rust-piscine-solutions/name_initials"} \ No newline at end of file diff --git a/rust/tests/name_initials_test/src/main.rs b/rust/tests/name_initials_test/src/main.rs deleted file mode 100644 index 1fe75427..00000000 --- a/rust/tests/name_initials_test/src/main.rs +++ /dev/null @@ -1,128 +0,0 @@ -/* -## name_initials - -### Instructions - -Create a function called `initials`, this function will receive a vector of string literals -with names and return a vector of Strings with the initials of each name. - -### 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 - -*/ - -#[global_allocator] -static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; - -#[allow(unused_imports)] -use name_initials::*; - -#[allow(dead_code)] -fn main() { - let mut names = vec!["Harry Potter", "Someone Else", "J. L.", "Barack Obama"]; - println!("{:?}", initials(&mut names)); - // output: ["H. P.", "S. E.", "J. L.", "B. O."] -} - -#[allow(unused_imports)] -use jemalloc_ctl::{epoch, stats}; - -#[allow(dead_code)] -struct Test<'a> { - names: Vec<&'a str>, - result: Vec<&'a str>, -} - -// solution that will run against the students solution -// this function uses the less heap allocation -#[allow(dead_code)] -fn initials_sol(arr: &mut Vec<&str>) -> Vec { - arr.iter() - .map(|ele| { - let mut names = ele.split_whitespace(); - let mut a = names.next().unwrap().chars().nth(0).unwrap().to_string(); - a.push_str(". "); - let mut b = names.next().unwrap().chars().nth(0).unwrap().to_string(); - b.push_str("."); - a.push_str(&b); - a - }) - .collect() -} - -#[test] -fn test_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 mut test_value = vec![ - "Lee Silva", - "Harry Potter", - "Someone Else", - "J. L.", - "Barack Obama", - ]; - - initials_sol(&mut 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(); - - initials(&mut 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![ - Test { - names: vec!["Harry Potter", "Someone Else", "J. L.", "Barack Obama"], - result: vec!["H. P.", "S. E.", "J. L.", "B. O."], - }, - Test { - names: vec![ - "James John", - "David Joseph", - "Matthew Brian", - "Jacob Sousa", - "Bruce Banner", - "Scarlett Johansson", - "Graydon Hoare", - ], - result: vec![ - "J. J.", "D. J.", "M. B.", "J. S.", "B. B.", "S. J.", "G. H.", - ], - }, - ]; - - for mut v in cases { - assert_eq!( - initials(&mut v.names), - v.result - .iter() - .map(|ele| ele.to_string()) - .collect::>() - ); - } -} diff --git a/rust/tests/ordinal_test/Cargo.lock b/rust/tests/ordinal_test/Cargo.lock deleted file mode 100644 index 90186920..00000000 --- a/rust/tests/ordinal_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "ordinal" -version = "0.1.0" - -[[package]] -name = "ordinal_test" -version = "0.1.0" -dependencies = [ - "ordinal", -] diff --git a/rust/tests/ordinal_test/Cargo.toml b/rust/tests/ordinal_test/Cargo.toml deleted file mode 100644 index 4caa56df..00000000 --- a/rust/tests/ordinal_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "ordinal_test" -version = "0.1.0" -authors = ["MSilva95 "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -ordinal = { path = "../../../../rust-piscine-solutions/ordinal"} diff --git a/rust/tests/ordinal_test/src/main.rs b/rust/tests/ordinal_test/src/main.rs deleted file mode 100644 index 37defdc2..00000000 --- a/rust/tests/ordinal_test/src/main.rs +++ /dev/null @@ -1,27 +0,0 @@ -/* -## ordinal - -### Instructions - -Complete the function "num_to_ordinal" that receives a cardinal number and returns its ordinal number. - -*/ -use ordinal::*; - -fn main() { - println!("{}", num_to_ordinal(1)); - println!("{}", num_to_ordinal(22)); - println!("{}", num_to_ordinal(43)); - println!("{}", num_to_ordinal(47)); -} - -#[test] -fn test_num_to_ordinal() { - assert_eq!(num_to_ordinal(0), "0th"); - assert_eq!(num_to_ordinal(1), "1st"); - assert_eq!(num_to_ordinal(12), "12th"); - assert_eq!(num_to_ordinal(22), "22nd"); - assert_eq!(num_to_ordinal(43), "43rd"); - assert_eq!(num_to_ordinal(67), "67th"); - assert_eq!(num_to_ordinal(1901), "1901st"); -} diff --git a/rust/tests/ownership_test/Cargo.lock b/rust/tests/ownership_test/Cargo.lock deleted file mode 100644 index 9cf48260..00000000 --- a/rust/tests/ownership_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "ownership" -version = "0.1.0" - -[[package]] -name = "ownership_test" -version = "0.1.0" -dependencies = [ - "ownership", -] diff --git a/rust/tests/ownership_test/Cargo.toml b/rust/tests/ownership_test/Cargo.toml deleted file mode 100644 index a724362b..00000000 --- a/rust/tests/ownership_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "ownership_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -ownership = { path = "../../../../rust-piscine-solutions/ownership"} diff --git a/rust/tests/ownership_test/src/main.rs b/rust/tests/ownership_test/src/main.rs deleted file mode 100644 index ebaeef61..00000000 --- a/rust/tests/ownership_test/src/main.rs +++ /dev/null @@ -1,64 +0,0 @@ -/* -## ownership - -### Instruction - -Create a function that takes ownership of a string and returns the -first sub-word in it. It should work for camelCase as well as snake_case -first_subword(camelCase) returns camel -first_subword(snake_case) returns snake - -And fix the printing expression so the code works - -### -*/ - -use ownership::*; - -fn main() { - let s1 = String::from("helloWorld"); - let s2 = String::from("snake_case"); - let s3 = String::from("CamelCase"); - let s4 = String::from("just"); - - println!("first_subword({}) = {}", s1.clone(), first_subword(s1)); // Must print first_subword(helloWorld) = hello - println!("first_subword({}) = {}", s2.clone(), first_subword(s2)); // Must print first_subword(snake_case) = snake - println!("first_subword({}) = {}", s3.clone(), first_subword(s3)); // Must print first_subword(CamelCase) = Camel - println!("first_subword({}) = {}", s4.clone(), first_subword(s4)); // Must print first_subword(just) = just -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn first_subword_test() { - struct TstString<'a> { - str: String, - l: &'a str, - } - - let o_tsts = vec![ - TstString { - str: "helloWorld".to_string(), - l: "hello", - }, - TstString { - str: "how_you".to_string(), - l: "how", - }, - TstString { - str: "Changeyou".to_string(), - l: "Changeyou", - }, - TstString { - str: "CamelCase".to_string(), - l: "Camel", - }, - ]; - - for t in o_tsts.iter() { - assert_eq!(t.l.to_string(), first_subword(t.str.clone())); - } - } -} diff --git a/rust/tests/pangram_test/Cargo.lock b/rust/tests/pangram_test/Cargo.lock deleted file mode 100644 index 23f0b920..00000000 --- a/rust/tests/pangram_test/Cargo.lock +++ /dev/null @@ -1,13 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "pangram" -version = "0.1.0" - -[[package]] -name = "pangram_test" -version = "0.1.0" -dependencies = [ - "pangram 0.1.0", -] - diff --git a/rust/tests/pangram_test/Cargo.toml b/rust/tests/pangram_test/Cargo.toml deleted file mode 100644 index c3871005..00000000 --- a/rust/tests/pangram_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "pangram_test" -version = "0.1.0" -authors = ["MSilva95 "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -pangram = { path = "../../../../rust-piscine-solutions/pangram"} diff --git a/rust/tests/pangram_test/src/main.rs b/rust/tests/pangram_test/src/main.rs deleted file mode 100644 index 44b76116..00000000 --- a/rust/tests/pangram_test/src/main.rs +++ /dev/null @@ -1,56 +0,0 @@ -/* -## pangram - -### Instructions - -Determine if the string is a pangram. -A pangram is a sentence using every letter of the alphabet at least once. - -Example: - -"The quick brown fox jumps over the lazy dog." - -*/ -use pangram::*; -use std::collections::HashSet; - -fn main() { - println!( - "{}", - is_pangram("the quick brown fox jumps over the lazy dog!") - ); - println!("{}", is_pangram("this is not a pangram!")); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_empty_strings() { - assert!(!is_pangram("")); - assert!(!is_pangram(" ")); - } - - #[test] - fn test_is_pangram() { - assert!(is_pangram("the quick brown fox jumps over the lazy dog")); - assert!(is_pangram("the_quick_brown_fox_jumps_over_the_lazy_dog")); - assert!(is_pangram( - "the 1 quick brown fox jumps over the 2 lazy dogs" - )); - } - #[test] - fn test_not_pangram() { - assert!(!is_pangram( - "a quick movement of the enemy will jeopardize five gunboats" - )); - assert!(!is_pangram("the quick brown fish jumps over the lazy dog")); - assert!(!is_pangram("the quick brown fox jumps over the lay dog")); - assert!(!is_pangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")); - assert!(is_pangram("\"Five quacking Zephyrs jolt my wax bed.\"")); - assert!(is_pangram( - "Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich." - )); - } -} diff --git a/rust/tests/panic_test/Cargo.lock b/rust/tests/panic_test/Cargo.lock deleted file mode 100644 index 48ea8173..00000000 --- a/rust/tests/panic_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "panic" -version = "0.1.0" - -[[package]] -name = "panic_test" -version = "0.1.0" -dependencies = [ - "panic", -] diff --git a/rust/tests/panic_test/Cargo.toml b/rust/tests/panic_test/Cargo.toml deleted file mode 100644 index 46274a8d..00000000 --- a/rust/tests/panic_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "panic_test" -version = "0.1.0" -authors = ["lee "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -panic = { path = "../../../../rust-piscine-solutions/panic"} \ No newline at end of file diff --git a/rust/tests/panic_test/src/main.rs b/rust/tests/panic_test/src/main.rs deleted file mode 100644 index 96620325..00000000 --- a/rust/tests/panic_test/src/main.rs +++ /dev/null @@ -1,29 +0,0 @@ -use panic::*; -use std::fs::{self, File}; - -fn main() { - let filename = "created.txt"; - File::create(filename).unwrap(); - let a = open_file(filename); - println!("{:?}", a); - fs::remove_file(filename).unwrap(); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - #[should_panic] - fn test_opening() { - open_file("file.txt"); - } - - #[test] - fn test_opening_existing() { - let filename = "created.txt"; - File::create(filename).unwrap(); - open_file(filename); - fs::remove_file(filename).unwrap(); - } -} diff --git a/rust/tests/pig_latin_test/Cargo.lock b/rust/tests/pig_latin_test/Cargo.lock deleted file mode 100644 index 4db018cf..00000000 --- a/rust/tests/pig_latin_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "pig_latin" -version = "0.1.0" - -[[package]] -name = "pig_latin_test" -version = "0.1.0" -dependencies = [ - "pig_latin", -] diff --git a/rust/tests/pig_latin_test/Cargo.toml b/rust/tests/pig_latin_test/Cargo.toml deleted file mode 100644 index 51dffa34..00000000 --- a/rust/tests/pig_latin_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "pig_latin_test" -version = "0.1.0" -authors = ["MSilva95 "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -pig_latin = { path = "../../../../rust-piscine-solutions/pig_latin"} diff --git a/rust/tests/pig_latin_test/src/main.rs b/rust/tests/pig_latin_test/src/main.rs deleted file mode 100644 index ebd11306..00000000 --- a/rust/tests/pig_latin_test/src/main.rs +++ /dev/null @@ -1,59 +0,0 @@ - -/* -## pig_latin - -### Instructions - -Write a function that transforms a string passed as argument in its `Pig Latin` version. - -The rules used by Pig Latin are the following: - -- If a word begins with a vowel, just add "ay" to the end. -- If it begins with a consonant, then we take all consonants before the first vowel and we put them on the end of the word and add "ay" at the end. -- If a word starts with a consonant followed by "qu", move it to the end of the word, and then add an "ay" sound to the end of the word (e.g. "square" -> "aresquay"). - -### Notions - -- https://doc.rust-lang.org/book/ch18-00-patterns.html - -*/ -use pig_latin::*; -fn main() { - println!("{}", pig_latin(&String::from("igloo"))); - println!("{}", pig_latin(&String::from("apple"))); - println!("{}", pig_latin(&String::from("hello"))); - println!("{}", pig_latin(&String::from("square"))); - println!("{}", pig_latin(&String::from("xenon"))); - println!("{}", pig_latin(&String::from("chair"))); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_word_beginning_with_vowel() { - assert_eq!(pig_latin(&String::from("apple")), "appleay"); - assert_eq!(pig_latin(&String::from("ear")), "earay"); - assert_eq!(pig_latin(&String::from("igloo")), "iglooay"); - assert_eq!(pig_latin(&String::from("object")), "objectay"); - assert_eq!(pig_latin(&String::from("under")), "underay"); - } - - #[test] - - fn test_word_beginning_with_consonant() { - assert_eq!(pig_latin(&String::from("queen")), "eenquay"); - assert_eq!(pig_latin(&String::from("square")), "aresquay"); - assert_eq!(pig_latin(&String::from("equal")), "equalay"); - assert_eq!(pig_latin(&String::from("pig")), "igpay"); - assert_eq!(pig_latin(&String::from("koala")), "oalakay"); - assert_eq!(pig_latin(&String::from("yellow")), "ellowyay"); - assert_eq!(pig_latin(&String::from("xenon")), "enonxay"); - assert_eq!(pig_latin(&String::from("qat")), "atqay"); - assert_eq!(pig_latin(&String::from("chair")), "airchay"); - assert_eq!(pig_latin(&String::from("therapy")), "erapythay"); - assert_eq!(pig_latin(&String::from("thrush")), "ushthray"); - assert_eq!(pig_latin(&String::from("school")), "oolschay"); - } -} \ No newline at end of file diff --git a/rust/tests/profanity_filter_test/Cargo.lock b/rust/tests/profanity_filter_test/Cargo.lock deleted file mode 100644 index f4fb40ac..00000000 --- a/rust/tests/profanity_filter_test/Cargo.lock +++ /dev/null @@ -1,99 +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 = "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 = "profanity_filter" -version = "0.1.0" -dependencies = [ - "chrono", -] - -[[package]] -name = "profanity_filter_test" -version = "0.1.0" -dependencies = [ - "chrono", - "profanity_filter", -] - -[[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" diff --git a/rust/tests/profanity_filter_test/Cargo.toml b/rust/tests/profanity_filter_test/Cargo.toml deleted file mode 100644 index 955cc920..00000000 --- a/rust/tests/profanity_filter_test/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "profanity_filter_test" -version = "0.1.0" -authors = ["lee "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -profanity_filter = { path = "../../../../rust-piscine-solutions/profanity_filter"} -chrono = "0.4.19" diff --git a/rust/tests/profanity_filter_test/src/main.rs b/rust/tests/profanity_filter_test/src/main.rs deleted file mode 100644 index 7a10ca74..00000000 --- a/rust/tests/profanity_filter_test/src/main.rs +++ /dev/null @@ -1,77 +0,0 @@ -use profanity_filter::*; - -fn main() { - let m0 = Message::new("hello there".to_string(), "toby".to_string(), format_date()); - println!("{:?}", check_ms(&m0)); - // output: (true, "hello there") - - let m1 = Message::new("".to_string(), "toby".to_string(), format_date()); - println!("{:?}", check_ms(&m1)); - // output: (false, "ERROR: illegal") - - let m2 = Message::new("you are stupid".to_string(), "toby".to_string(), format_date()); - println!("{:?}", check_ms(&m2)); - // output: (false, "ERROR: illegal") - - let m3 = Message::new("stupid".to_string(), "toby".to_string(), format_date()); - println!("{:?}", check_ms(&m3)); - // output: (false, "ERROR: illegal") -} - -#[cfg(test)] -mod tests { - use super::*; - use chrono::prelude::Utc; - - fn test_format() -> String { - Utc::now().format("%a %b %e %T %Y").to_string() - } - - #[test] - fn test_time_format() { - assert_eq!(format_date(), test_format()); - } - - #[test] - fn test_error_ms() { - let v = vec![ - Message::new("".to_string(), "toby".to_string(), format_date()), - Message::new("stupid".to_string(), "jack".to_string(), format_date()), - Message::new( - "you are stupid".to_string(), - "jacob".to_string(), - format_date(), - ), - ]; - for value in v { - let (t, _) = check_ms(&value); - assert!(!t); - } - } - - #[test] - fn test_ok_ms() { - let v = vec![ - Message::new( - "get out of the car".to_string(), - "police".to_string(), - format_date(), - ), - Message::new("no!".to_string(), "thief".to_string(), format_date()), - Message::new( - "get the werewolf".to_string(), - "police".to_string(), - format_date(), - ), - Message::new( - "wait the wha...".to_string(), - "thief".to_string(), - format_date(), - ), - ]; - for value in v { - let (t, _) = check_ms(&value); - assert!(t); - } - } -} diff --git a/rust/tests/project_motion_test/Cargo.lock b/rust/tests/project_motion_test/Cargo.lock deleted file mode 100644 index 5e0f535f..00000000 --- a/rust/tests/project_motion_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "project_motion" -version = "0.1.0" - -[[package]] -name = "project_motion_test" -version = "0.1.0" -dependencies = [ - "project_motion", -] diff --git a/rust/tests/project_motion_test/Cargo.toml b/rust/tests/project_motion_test/Cargo.toml deleted file mode 100644 index b088cb33..00000000 --- a/rust/tests/project_motion_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "project_motion_test" -version = "0.1.0" -authors = ["lee "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -project_motion = { path = "../../../../rust-piscine-solutions/project_motion"} diff --git a/rust/tests/project_motion_test/src/main.rs b/rust/tests/project_motion_test/src/main.rs deleted file mode 100644 index 13d4c146..00000000 --- a/rust/tests/project_motion_test/src/main.rs +++ /dev/null @@ -1,56 +0,0 @@ -use project_motion::*; - -fn main() { - let mut obj = Object::throw_object(50.0, 150.0); - println!("{:?}", obj.next()); - println!("{:?}", obj.next()); - println!("{:?}", obj.next()); - println!("{:?}", obj.next()); - println!("{:?}", obj.next()); - println!("{:?}", obj.next()); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_short_distance() { - let mut object = Object::throw_object(50.0, 20.0); - - assert_eq!(object.next(), Some(Object { distance: 50.0, velocity: 50.0, height: 15.1, time: 1.0 })); - assert_eq!(object, Object { distance: 50.0, velocity: 50.0, height: 15.1, time: 1.0 }); - - assert!(object.next().is_none(), "{:?} instead of None", object); - assert!(object.next().is_none(), "{:?} instead of None", object); - } - - #[test] - fn test_media_distance() { - let mut object = Object::throw_object(100.0, 30.0); - - assert_eq!(object.next(), Some(Object { distance: 100.0, velocity: 100.0, height: 25.1, time: 1.0 })); - assert_eq!(object, Object { distance: 100.0, velocity: 100.0, height: 25.1, time: 1.0 }); - - assert_eq!(object.next(), Some(Object { distance: 200.0, velocity: 100.0, height: 5.5, time: 2.0 })); - assert_eq!(object, Object { distance: 200.0, velocity: 100.0, height: 5.5, time: 2.0 }); - - assert!(object.next().is_none(), "{:?} instead of None", object); - } - - #[test] - fn test_long_distance() { - let mut object = Object::throw_object(120.0, 100.0); - - assert_eq!(object.next(), Some(Object { distance: 120.0, velocity: 120.0, height: 95.1, time: 1.0 })); - assert_eq!(object, Object { distance: 120.0, velocity: 120.0, height: 95.1, time: 1.0 }); - - assert_eq!(object.next(), Some(Object { distance: 240.0, velocity: 120.0, height: 75.5, time: 2.0 })); - assert_eq!(object, Object { distance: 240.0, velocity: 120.0, height: 75.5, time: 2.0 }); - - assert_eq!(object.next(), Some(Object { distance: 360.0, velocity: 120.0, height: 31.4, time: 3.0 })); - assert_eq!(object, Object { distance: 360.0, velocity: 120.0, height: 31.4, time: 3.0 }); - - assert!(object.next().is_none(), "{:?} instead of None", object); - } -} diff --git a/rust/tests/question_mark_test/Cargo.lock b/rust/tests/question_mark_test/Cargo.lock deleted file mode 100644 index 1fbf15c0..00000000 --- a/rust/tests/question_mark_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "question_mark" -version = "0.1.0" - -[[package]] -name = "question_mark_test" -version = "0.1.0" -dependencies = [ - "question_mark", -] diff --git a/rust/tests/question_mark_test/Cargo.toml b/rust/tests/question_mark_test/Cargo.toml deleted file mode 100644 index d970a526..00000000 --- a/rust/tests/question_mark_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "question_mark_test" -version = "0.1.0" -authors = ["lee "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -question_mark = { path = "../../../../rust-piscine-solutions/question_mark"} diff --git a/rust/tests/question_mark_test/src/main.rs b/rust/tests/question_mark_test/src/main.rs deleted file mode 100644 index c2398e29..00000000 --- a/rust/tests/question_mark_test/src/main.rs +++ /dev/null @@ -1,47 +0,0 @@ -use question_mark::*; - -fn main() { - let a = One { - first_layer : Some(Two { - second_layer: Some(Three { - third_layer: Some(Four { - fourth_layer: Some(1000) - }) - }) - }) - }; - - // output: 1000 - println!("{:?}", match a.get_fourth_layer() { - Some(e) => e, - None => 0 - }) -} - -#[cfg(test)] -mod tests { - use super::*; - #[test] - fn test_value() { - let a = One { - first_layer : Some(Two { - second_layer: Some(Three { - third_layer: Some(Four { - fourth_layer: Some(1000) - }) - }) - }) - }; - let b = One { - first_layer : Some(Two { - second_layer: Some(Three { - third_layer: Some(Four { - fourth_layer: Some(3) - }) - }) - }) - }; - assert_eq!(a.get_fourth_layer(), Some(1000)); - assert_eq!(b.get_fourth_layer(), Some(3)); - } -} diff --git a/rust/tests/ref_cell_test/Cargo.lock b/rust/tests/ref_cell_test/Cargo.lock deleted file mode 100644 index 04f405cb..00000000 --- a/rust/tests/ref_cell_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "ref_cell" -version = "0.1.0" - -[[package]] -name = "ref_cell_test" -version = "0.1.0" -dependencies = [ - "ref_cell", -] diff --git a/rust/tests/ref_cell_test/Cargo.toml b/rust/tests/ref_cell_test/Cargo.toml deleted file mode 100644 index acacc6db..00000000 --- a/rust/tests/ref_cell_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "ref_cell_test" -version = "0.1.0" -authors = ["lee "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -ref_cell = { path = "../../../../rust-piscine-solutions/ref_cell"} diff --git a/rust/tests/ref_cell_test/src/main.rs b/rust/tests/ref_cell_test/src/main.rs deleted file mode 100644 index 9ba1908e..00000000 --- a/rust/tests/ref_cell_test/src/main.rs +++ /dev/null @@ -1,158 +0,0 @@ -use ref_cell::*; - -fn main() { - // initialize the worker - let Logger = Worker::new(1); - - // initialize the tracker, with the max number of - // called references as 10 - let track = Tracker::new(&Logger, 10); - - let _a = Logger.track_value.clone(); // |\ - let _a1 = Logger.track_value.clone(); // | -> increase the Rc to 4 references - let _a2 = Logger.track_value.clone(); // |/ - - // take a peek of how much we already used from our quota - track.peek(&Logger.track_value); - - let _b = Logger.track_value.clone(); // |\ - let _b1 = Logger.track_value.clone(); // | -> increase the Rc to 8 references - let _b2 = Logger.track_value.clone(); // | / - let _b3 = Logger.track_value.clone(); // |/ - - // this will set the value and making a verification of - // how much we already used of our quota - track.set_value(&Logger.track_value); - - let _c = Logger.track_value.clone(); // | -> increase the Rc to 9 references - - // this will set the value and making a verification of - // how much we already used of our quota - track.set_value(&Logger.track_value); - - let _c1 = Logger.track_value.clone(); // | -> increase the Rc to 10 references, this will be the limit - - track.set_value(&Logger.track_value); - - for (k ,v) in Logger.mapped_messages.into_inner() { - println!("{:?}", (k ,v)); - } - println!("{:?}", Logger.all_messages.into_inner()); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_module() { - #[derive(Clone, Debug)] - struct TestMs { - value: Rc, - ms: RefCell>, - correct: Vec, - } - - impl Logger for TestMs { - fn warning(&self, message: &str) { - self.ms.borrow_mut().push(message.to_string()); - } - fn info(&self, message: &str) { - self.ms.borrow_mut().push(message.to_string()); - } - fn error(&self, message: &str) { - self.ms.borrow_mut().push(message.to_string()); - } - } - - let l = TestMs { - value: Rc::new(115), - ms: RefCell::new(vec![]), - correct: vec![ - String::from("Info: you are using up too 40% of your quote"), - String::from("Warning: you have used up over 80% of your quota! Proceeds with precaution"), - String::from("Error: you are over your quota!") - ], - }; - - let track = Tracker::new(&l, 5); - let _a = l.value.clone(); - track.peek(&l.value); // 40% - let _a1 = l.value.clone(); - let _a2 = l.value.clone(); - track.set_value(&l.value); // 80% - let _a3 = l.value.clone(); - track.set_value(&l.value); // 100% - - for (i, v) in l.ms.into_inner().iter().enumerate() { - assert_eq!(v, &l.correct[i]) - } - } - - #[test] - fn test_module_usage_hasmap() { - let log = Worker::new(1000); - let track = Tracker::new(&log, 12); - let _clone_test = log.track_value.clone(); - let _clone_test1 = log.track_value.clone(); - let _clone_test2 = log.track_value.clone(); - let _clone_test3 = log.track_value.clone(); - let _clone_test4 = log.track_value.clone(); - let _clone_test5 = log.track_value.clone(); - let _clone_test6 = log.track_value.clone(); - let _clone_test7 = log.track_value.clone(); - - // warning: 75% of the quota - track.set_value(&log.track_value); - assert_eq!(log.mapped_messages.borrow().get("Warning").unwrap(), "you have used up over 75% of your quota! Proceeds with precaution"); - - let _clone_test8 = log.track_value.clone(); - - // warning: 83% of the quota <- most resent of the messages last onw to be added to the hashmap - track.set_value(&log.track_value); - assert_eq!(log.mapped_messages.borrow().get("Warning").unwrap(), "you have used up over 83% of your quota! Proceeds with precaution"); - - // info: 83% - track.peek(&log.track_value); - assert_eq!(log.mapped_messages.borrow().get("Info").unwrap(), "you are using up too 83% of your quote"); - - let _clone_test9 = log.track_value.clone(); - // info: 91% - track.peek(&log.track_value); - assert_eq!(log.mapped_messages.borrow().get("Info").unwrap(), "you are using up too 91% of your quote"); - - let _clone_test10 = log.track_value.clone(); - // error: passed the quota - track.set_value(&log.track_value); - assert_eq!(log.mapped_messages.borrow().get("Error").unwrap(), "you are over your quota!"); - } - - #[test] - fn test_module_usage_vector() { - let correct = vec![ - "Info: you are using up too 40% of your quote", - "Warning: you have used up over 80% of your quota! Proceeds with precaution", - "Info: you are using up too 80% of your quote", "Error: you are over your quota!" - ]; - let log = Worker::new(1); - let track = Tracker::new(&log, 5); - let _a = log.track_value.clone(); - // info: 40% - track.peek(&log.track_value); - let _a1 = log.track_value.clone(); - let _a2 = log.track_value.clone(); - - // warning: 80% - track.set_value(&log.track_value); - // info: 80% - track.peek(&log.track_value); - let _a3 = log.track_value.clone(); - - // error: passed the quota - track.set_value(&log.track_value); - - for (i, v) in log.all_messages.into_inner().iter().enumerate() { - assert_eq!(v, correct[i]); - } - } -} diff --git a/rust/tests/reverse_string_test/Cargo.lock b/rust/tests/reverse_string_test/Cargo.lock deleted file mode 100644 index 312c2248..00000000 --- a/rust/tests/reverse_string_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "reverse-string_test" -version = "0.1.0" -dependencies = [ - "reverse_string", -] - -[[package]] -name = "reverse_string" -version = "0.1.0" diff --git a/rust/tests/reverse_string_test/Cargo.toml b/rust/tests/reverse_string_test/Cargo.toml deleted file mode 100644 index 5ea26d98..00000000 --- a/rust/tests/reverse_string_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "reverse_string_test" -version = "0.1.0" -authors = ["MSilva95 "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -reverse_string = { path = "../../../../rust-piscine-solutions/reverse_string"} \ No newline at end of file diff --git a/rust/tests/reverse_string_test/src/main.rs b/rust/tests/reverse_string_test/src/main.rs deleted file mode 100644 index be9fc33e..00000000 --- a/rust/tests/reverse_string_test/src/main.rs +++ /dev/null @@ -1,39 +0,0 @@ -// Write a function `rev_str` that takes a `&str` as a parameter, and returns a string with its words reversed. -use reverse_string::rev_str; - -#[allow(dead_code)] -fn main() { - println!("{}", rev_str("Hello, world!")); - println!("{}", rev_str("Hello, my name is Roman")); - println!("{}", rev_str("I have a nice car!")); - println!("{}", rev_str("How old are You")); - println!("{}", rev_str("ex: this is an example água")); -} - - -#[allow(dead_code)] -fn test_reverse(input: &str, expected: &str) { - assert_eq!(&rev_str(input), expected); -} - -#[test] -// testing just one word -fn test_simple_word() { - test_reverse("robot", "tobor"); - test_reverse("Ramen", "nemaR"); - test_reverse("I'm hungry!", "!yrgnuh m'I"); - test_reverse("racecar", "racecar"); - test_reverse("drawer", "reward"); - test_reverse("子猫", "猫子"); - test_reverse("", ""); -} - -#[test] -// testing two or more words -fn test_more_than_one() { - test_reverse("Hello, world!", "!dlrow ,olleH"); - test_reverse("Hello, my name is Roman", "namoR si eman ym ,olleH"); - test_reverse("I have a nice car!", "!rac ecin a evah I"); - test_reverse("How old are You", "uoY era dlo woH"); - test_reverse("ex: this is an example água", "augá elpmaxe na si siht :xe"); -} diff --git a/rust/tests/rgb_match_test/Cargo.lock b/rust/tests/rgb_match_test/Cargo.lock deleted file mode 100644 index fb584311..00000000 --- a/rust/tests/rgb_match_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "rgb_match" -version = "0.1.0" - -[[package]] -name = "rgb_match_test" -version = "0.1.0" -dependencies = [ - "rgb_match", -] diff --git a/rust/tests/rgb_match_test/Cargo.toml b/rust/tests/rgb_match_test/Cargo.toml deleted file mode 100644 index 651a5fb2..00000000 --- a/rust/tests/rgb_match_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "rgb_match_test" -version = "0.1.0" -authors = ["MSilva95 "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -rgb_match = { path = "../../../../rust-piscine-solutions/rgb_match"} diff --git a/rust/tests/rgb_match_test/src/main.rs b/rust/tests/rgb_match_test/src/main.rs deleted file mode 100644 index 5d9e58f3..00000000 --- a/rust/tests/rgb_match_test/src/main.rs +++ /dev/null @@ -1,169 +0,0 @@ -/* -## rgb_match - -### Instructions - -Implement the struct `Color` with the function `swap`. -This function must allow you to swap the values of the struct. - -### Example: - -If the struct has this values -> Color { r: 255,g: 200,b: 10,a: 30,} and -you want to `swap(c.a, c.g)` you will get -> Color { r: 255, g: 30, b: 10, a: 200 } -*/ -use rgb_match::*; - -fn main() { - let c = Color { - r: 255, - g: 200, - b: 10, - a: 30, - }; - - println!("{:?}", c.swap(c.r, c.b)); - println!("{:?}", c.swap(c.r, c.g)); - println!("{:?}", c.swap(c.r, c.a)); - println!(); - println!("{:?}", c.swap(c.g, c.r)); - println!("{:?}", c.swap(c.g, c.b)); - println!("{:?}", c.swap(c.g, c.a)); - println!(); - println!("{:?}", c.swap(c.b, c.r)); - println!("{:?}", c.swap(c.b, c.g)); - println!("{:?}", c.swap(c.b, c.a)); - println!(); - println!("{:?}", c.swap(c.a, c.r)); - println!("{:?}", c.swap(c.a, c.b)); - println!("{:?}", c.swap(c.a, c.g)); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_one() { - let c = Color { - r: 255, - g: 200, - b: 10, - a: 30, - }; - // swap r - assert_eq!( - c.swap(c.r, c.b), - Color { - r: 10, - g: 200, - b: 255, - a: 30 - } - ); - assert_eq!( - c.swap(c.r, c.g), - Color { - r: 200, - g: 255, - b: 10, - a: 30 - } - ); - assert_eq!( - c.swap(c.r, c.a), - Color { - r: 30, - g: 200, - b: 10, - a: 255 - } - ); - - // swap g - assert_eq!( - c.swap(c.g, c.r), - Color { - r: 200, - g: 255, - b: 10, - a: 30 - } - ); - assert_eq!( - c.swap(c.g, c.b), - Color { - r: 255, - g: 10, - b: 200, - a: 30 - } - ); - assert_eq!( - c.swap(c.g, c.a), - Color { - r: 255, - g: 30, - b: 10, - a: 200 - } - ); - - // swap b - assert_eq!( - c.swap(c.b, c.r), - Color { - r: 10, - g: 200, - b: 255, - a: 30 - } - ); - assert_eq!( - c.swap(c.b, c.g), - Color { - r: 255, - g: 10, - b: 200, - a: 30 - } - ); - assert_eq!( - c.swap(c.b, c.a), - Color { - r: 255, - g: 200, - b: 30, - a: 10 - } - ); - - // swap a - assert_eq!( - c.swap(c.a, c.r), - Color { - r: 30, - g: 200, - b: 10, - a: 255 - } - ); - assert_eq!( - c.swap(c.a, c.b), - Color { - r: 255, - g: 200, - b: 30, - a: 10 - } - ); - assert_eq!( - c.swap(c.a, c.g), - Color { - r: 255, - g: 30, - b: 10, - a: 200 - } - ); - } -} diff --git a/rust/tests/roman_numbers_iter_test/Cargo.lock b/rust/tests/roman_numbers_iter_test/Cargo.lock deleted file mode 100644 index a532508e..00000000 --- a/rust/tests/roman_numbers_iter_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "roman_numbers" -version = "0.1.0" - -[[package]] -name = "roman_numbers_test" -version = "0.1.0" -dependencies = [ - "roman_numbers", -] diff --git a/rust/tests/roman_numbers_iter_test/Cargo.toml b/rust/tests/roman_numbers_iter_test/Cargo.toml deleted file mode 100644 index 195c8f67..00000000 --- a/rust/tests/roman_numbers_iter_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "roman_numbers_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -roman_numbers = { path = "../../../../rust-piscine-solutions/roman_numbers"} diff --git a/rust/tests/roman_numbers_iter_test/src/main.rs b/rust/tests/roman_numbers_iter_test/src/main.rs deleted file mode 100644 index 8d9ed8cf..00000000 --- a/rust/tests/roman_numbers_iter_test/src/main.rs +++ /dev/null @@ -1,85 +0,0 @@ -// # Instructions -// Implement the IntoIterator trait for the `RomanNumber` type to -// enable using a for loop notation. -// This implementation must allow taking ownership, -// borrowing and borrowing mutably - -// I.e. this three constructions must be possible -// ```rust -// let number = RomanNumber::from(23); - -// 1. Taking ownership (this consumes the RomanNumber) -// for digit in number { -// ... -// } - -// 2. Borrowing immutably (this preserves the RomanNumber) -// for digit in &number { - -// } - -// 3. Borrowing mutably (this allow you to modify the RomanNumber -// without having to return the ownership) -// for digit in &mut number { - -// } - -// Start with your research See https://doc.rust-lang.org/std/iter/trait.IntoIterator.html -// https://doc.rust-lang.org/std/iter/index.html - -use roman_numbers::{RomanDigit, RomanNumber}; - -fn main() { - let number = RomanNumber::from(15); - - for digit in &number { - println!("{:?}", digit); - } - println!("{:?}", number); -} - -#[allow(dead_code)] -fn into_u32(n: RomanDigit) -> u32 { - use RomanDigit::*; - match n { - Nulla => 0, - I => 1, - V => 5, - X => 10, - L => 50, - C => 100, - D => 500, - M => 1000, - } -} - -#[test] -fn test_iter() { - let number = RomanNumber::from(15); - - for digit in &number { - println!("{:?}", digit); - } - println!("{:?}", number); -} - -#[test] -fn test_into_iter() { - let number = RomanNumber::from(37); - let value: u32 = number.into_iter().map(|digit| into_u32(digit)).sum(); - println!("value: {}", value); -} - -#[test] -fn test_iter_mut() { - let mut number = RomanNumber::from(22); - - for digit in &mut number { - let value = into_u32(*digit); - *digit = dbg!(RomanNumber::from(value - 1)).0[0]; - } - println!( - "Roman Number after increasing the each digit by 1 = {:?}", - number - ); -} diff --git a/rust/tests/roman_numbers_test/Cargo.lock b/rust/tests/roman_numbers_test/Cargo.lock deleted file mode 100644 index a532508e..00000000 --- a/rust/tests/roman_numbers_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "roman_numbers" -version = "0.1.0" - -[[package]] -name = "roman_numbers_test" -version = "0.1.0" -dependencies = [ - "roman_numbers", -] diff --git a/rust/tests/roman_numbers_test/Cargo.toml b/rust/tests/roman_numbers_test/Cargo.toml deleted file mode 100644 index 195c8f67..00000000 --- a/rust/tests/roman_numbers_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "roman_numbers_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -roman_numbers = { path = "../../../../rust-piscine-solutions/roman_numbers"} diff --git a/rust/tests/roman_numbers_test/src/main.rs b/rust/tests/roman_numbers_test/src/main.rs deleted file mode 100644 index bee51375..00000000 --- a/rust/tests/roman_numbers_test/src/main.rs +++ /dev/null @@ -1,49 +0,0 @@ -// # Instructions -// Implement the From Trait to create a roman number from a u32 -// the roman number should be in subtractive notation (the common way to write roman -// number I, II, II, IV, V, VI, VII, VIII, IX, X ...) - -// For this start by defining the digits as `RomanDigit` with the values -// I, V, X, L, C, D, M and Nulla for 0 - -// Next define RomanNumber as a wrapper to a vector of RomanDigit's -// And implement the Trait From - -// Examples: -// RomanNumber::from(32) = [X,X,X,I,I] -// RomanNumber::from(9) = [I,X] -// RomanNumber::from(45) = [X,L,V] -// RomanNumber:;from(0) = [Nulla] - -#[allow(unused_imports)] -use roman_numbers::RomanDigit::*; -#[allow(unused_imports)] -use roman_numbers::RomanNumber; - -#[allow(dead_code)] -fn main() { - println!("{:?}", RomanNumber::from(32)); - println!("{:?}", RomanNumber::from(9)); - println!("{:?}", RomanNumber::from(45)); - println!("{:?}", RomanNumber::from(0)); -} -#[test] -fn it_works() { - assert_eq!(RomanNumber::from(3).0, [I, I, I]); - assert_eq!(RomanNumber::from(6).0, [V, I]); - assert_eq!(RomanNumber::from(15).0, [X, V]); - assert_eq!(RomanNumber::from(30).0, [X, X, X]); - assert_eq!(RomanNumber::from(150).0, [C, L]); - assert_eq!(RomanNumber::from(200).0, [C, C]); - assert_eq!(RomanNumber::from(600).0, [D, C]); - assert_eq!(RomanNumber::from(1500).0, [M, D]); -} - -#[test] -fn substractive_notation() { - assert_eq!(RomanNumber::from(4).0, [I, V]); - assert_eq!(RomanNumber::from(44).0, [X, L, I, V]); - assert_eq!(RomanNumber::from(3446).0, [M, M, M, C, D, X, L, V, I]); - assert_eq!(RomanNumber::from(9).0, [I, X]); - assert_eq!(RomanNumber::from(94).0, [X, C, I, V]); -} diff --git a/rust/tests/rot_test/Cargo.lock b/rust/tests/rot_test/Cargo.lock deleted file mode 100644 index ce43f615..00000000 --- a/rust/tests/rot_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "rot" -version = "0.1.0" - -[[package]] -name = "rot_test" -version = "0.1.0" -dependencies = [ - "rot", -] diff --git a/rust/tests/rot_test/Cargo.toml b/rust/tests/rot_test/Cargo.toml deleted file mode 100644 index 99ffa741..00000000 --- a/rust/tests/rot_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "rot_test" -version = "0.1.0" -authors = ["MSilva95 "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -rot = { path = "../../../../rust-piscine-solutions/rot"} diff --git a/rust/tests/rot_test/src/main.rs b/rust/tests/rot_test/src/main.rs deleted file mode 100644 index 445a4441..00000000 --- a/rust/tests/rot_test/src/main.rs +++ /dev/null @@ -1,98 +0,0 @@ -/* - ## rotate - -### Instructions - -By now you will have the knowledge of the so called rotational cipher "ROT13". - -A ROT13 on the Latin alphabet would be as follows: - -- Plain: abcdefghijklmnopqrstuvwxyz - -- Cipher: nopqrstuvwxyzabcdefghijklm - -Your purpose in this exercise is to create a similar `rotate` function that is a better version of the ROT13 cipher. -Your function will receive a string and a number and it will rotate each letter of that string, the number of times, settled by the second argument, to the right or to the left if the number are negative. - -Your function should only change letters. If the string includes punctuation and numbers -they will remain the same. - -### Notions - -- https://doc.rust-lang.org/book/ch18-00-patterns.html - -### Expected functions - -```rust - -``` - -### Usage - -Here is a program to test your function. -*/ -use rot::*; - -fn main() { - - println!("The letter \"a\" becomes: {}", rotate("a", 26)); - println!("The letter \"m\" becomes: {}", rotate("m", 0)); - println!("The letter \"m\" becomes: {}", rotate("m", 13)); - println!("The letter \"a\" becomes: {}", rotate("a", 15)); - println!("The word \"MISS\" becomes: {}", rotate("MISS", 5)); - println!( - "The decoded message is: {}", - rotate("Gur svir obkvat jvmneqf whzc dhvpxyl.", 13) - ); - println!( - "The decoded message is: {}", - rotate("Mtb vznhpqd ifky ozrunsl ejgwfx ajc", 5) - ); - println!( - "Your cypher wil be: {}", - rotate("Testing with numbers 1 2 3", 4) - ); - println!("Your cypher wil be: {}", rotate("Testing", -14)); - println!("The letter \"a\" becomes: {}", rotate("a", -1)); -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_simple() { - assert_eq!("z", rotate("m", 13)); - assert_eq!("n", rotate("m", 1)); - assert_eq!("a", rotate("a", 26)); - assert_eq!("z", rotate("a", 25)); - assert_eq!("b", rotate("l", 16)); - assert_eq!("j", rotate("j", 0)); - assert_eq!("RNXX", rotate("MISS", 5)); - assert_eq!("M J Q Q T", rotate("H E L L O", 5)); - } - - #[test] - fn test_all_letters() { - assert_eq!( - "Gur svir obkvat jvmneqf whzc dhvpxyl.", - rotate("The five boxing wizards jump quickly.", 13) - ); - } - - #[test] - fn test_numbers_punctuation() { - assert_eq!( - "Xiwxmrk amxl ryqfivw 1 2 3", - rotate("Testing with numbers 1 2 3", 4) - ); - assert_eq!("Gzo\'n zvo, Bmviyhv!", rotate("Let\'s eat, Grandma!", 21)); - } - - #[test] - fn test_negative() { - assert_eq!("z", rotate("a", -1)); - assert_eq!("W", rotate("A", -4)); - assert_eq!("Fqefuzs", rotate("Testing", -14)); - } -} diff --git a/rust/tests/sales_test/Cargo.lock b/rust/tests/sales_test/Cargo.lock deleted file mode 100644 index b3dffd2f..00000000 --- a/rust/tests/sales_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "sales" -version = "0.1.0" - -[[package]] -name = "sales_test" -version = "0.1.0" -dependencies = [ - "sales", -] diff --git a/rust/tests/sales_test/Cargo.toml b/rust/tests/sales_test/Cargo.toml deleted file mode 100644 index 42d70f49..00000000 --- a/rust/tests/sales_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "sales_test" -version = "0.1.0" -authors = ["lee "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -sales = { path = "../../../../rust-piscine-solutions/sales"} diff --git a/rust/tests/sales_test/src/main.rs b/rust/tests/sales_test/src/main.rs deleted file mode 100644 index ded9b1d9..00000000 --- a/rust/tests/sales_test/src/main.rs +++ /dev/null @@ -1,133 +0,0 @@ -use sales::*; - -fn main() { - let store = Store::new(vec![ - (String::from("product A"), 1.23), - (String::from("product B"), 23.1), - (String::from("product C"), 3.12)]); - - println!("{:?}", store); - // output: - // Store { products: [("product A", 1.23), ("product B", 23.1), ("product C", 3.12)] } - - let mut cart = Cart::new(); - cart.insert_item(&store, String::from("product A")); - cart.insert_item(&store, String::from("product B")); - cart.insert_item(&store, String::from("product C")); - - println!("{:?}", cart.generate_receipt()); - // output: - // [1.17, 2.98, 22.07] - - println!("{:?}", cart); - // output: - // Cart { items: [("product A", 1.23), ("product B", 23.1), ("product C", 3.12)], receipt: [1.17, 2.98, 22.07] } -} -#[cfg(test)] -mod tests { - use super::*; - - #[derive(Debug)] - struct Tests { - store: Store, - carts: Vec<(Cart, Vec)>, - } - - fn add_items(s: &Store, items: Vec<&str>, c: &mut Cart) { - for item in items.iter() { - c.insert_item(s, item.to_string()); - } - } - - impl Tests { - fn new() -> Tests { - let store = Store::new(vec![ - (String::from("product A"), 1.23), - (String::from("product B"), 23.1), - (String::from("product C"), 3.12), - (String::from("product D"), 9.75), - (String::from("product E"), 1.75), - (String::from("product F"), 23.75), - (String::from("product G"), 2.75), - (String::from("product H"), 1.64), - (String::from("product I"), 15.23), - (String::from("product J"), 2.10), - (String::from("product K"), 54.91), - (String::from("product L"), 43.99), - ]); - - let mut c = Cart::new(); - let mut c1 = Cart::new(); - let mut c2 = Cart::new(); - let mut c3 = Cart::new(); - add_items(&store, vec!["product A", "product B", "product C"], &mut c); - let sol = vec![1.17, 2.98, 22.07]; - add_items( - &store, - vec![ - "product A", - "product B", - "product C", - "product D", - "product E", - "product F", - "product G", - ], - &mut c1, - ); - let sol1 = vec![1.17, 1.67, 2.62, 2.98, 9.31, 22.05, 22.67]; - add_items( - &store, - vec![ - "product A", - "product B", - "product C", - "product D", - "product E", - "product F", - "product G", - "product H", - "product I", - ], - &mut c2, - ); - let sol2 = vec![1.16, 1.55, 1.65, 2.6, 2.94, 9.2, 14.38, 21.8, 22.42]; - add_items( - &store, - vec![ - "product A", - "product B", - "product C", - "product D", - "product E", - "product F", - "product G", - "product H", - "product I", - "product J", - "product K", - "product L", - ], - &mut c3, - ); - let sol3 = vec![ - 1.18, 1.58, 1.69, 2.02, 2.65, 3.01, 9.39, 14.67, 22.25, 22.88, 42.38, 52.89, - ]; - - Tests { - store, - carts: vec![(c, sol), (c1, sol1), (c2, sol2), (c3, sol3)], - } - } - } - - #[test] - fn test_generate_receipt() { - let cases = Tests::new(); - - for (mut c, sol) in cases.carts.into_iter() { - assert_eq!(c.generate_receipt(), sol); - assert_eq!(c.receipt, sol); - } - } -} diff --git a/rust/tests/scalar_test/Cargo.lock b/rust/tests/scalar_test/Cargo.lock deleted file mode 100644 index 5fa8333c..00000000 --- a/rust/tests/scalar_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "scalar" -version = "0.1.0" - -[[package]] -name = "scalar_test" -version = "0.1.0" -dependencies = [ - "scalar", -] diff --git a/rust/tests/scalar_test/Cargo.toml b/rust/tests/scalar_test/Cargo.toml deleted file mode 100644 index d45a77cb..00000000 --- a/rust/tests/scalar_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "scalar_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -scalar = {path = "../../../../rust-piscine-solutions/scalar"} diff --git a/rust/tests/scalar_test/src/main.rs b/rust/tests/scalar_test/src/main.rs deleted file mode 100644 index d7ebe1d9..00000000 --- a/rust/tests/scalar_test/src/main.rs +++ /dev/null @@ -1,28 +0,0 @@ -use scalar::*; - -#[test] -#[should_panic] -fn test_panic_sum() { - sum(25, 255); -} - -#[test] -#[should_panic] -fn test_panic_diff() { - diff(-32768, 32766); -} - -#[test] -#[should_panic] -fn test_panic_pro() { - pro(-128, 2); -} - -#[test] -fn pass() { - assert_eq!(sum(1, 2), 3); - assert_eq!(diff(1, 2), -1); - assert_eq!(pro(1, 2), 2); - assert_eq!(quo(1.0, 2.0), 0.5); - assert_eq!(rem(1.0, 2.0), 1.0); -} diff --git a/rust/tests/scores_test/Cargo.lock b/rust/tests/scores_test/Cargo.lock deleted file mode 100644 index 8455d4bd..00000000 --- a/rust/tests/scores_test/Cargo.lock +++ /dev/null @@ -1,13 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "scores" -version = "0.1.0" - -[[package]] -name = "scores_test" -version = "0.1.0" -dependencies = [ - "scores 0.1.0", -] - diff --git a/rust/tests/scores_test/Cargo.toml b/rust/tests/scores_test/Cargo.toml deleted file mode 100644 index 9309ecc7..00000000 --- a/rust/tests/scores_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "scores_test" -version = "0.1.0" -authors = ["MSilva95 "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -scores = { path = "../../../../rust-piscine-solutions/scores"} diff --git a/rust/tests/scores_test/src/main.rs b/rust/tests/scores_test/src/main.rs deleted file mode 100644 index 2cc07297..00000000 --- a/rust/tests/scores_test/src/main.rs +++ /dev/null @@ -1,68 +0,0 @@ -/* -## score - -### Instructions - -Lets play a little! -Create a function `score` that given a string, computes the score for that given string. -Each letter has their value, you just have to sum the values of the letters in the -given string. - -You'll need these: - -Letter Value -A, E, I, O, U, L, N, R, S, T 1 -D, G 2 -B, C, M, P 3 -F, H, V, W, Y 4 -K 5 -J, X 8 -Q, Z 10 - -### Examples - -So if yo pass the word "Hello" you will have the score 8 returned. -Any type of special character or punctuation marks has a value of 0 so if you have -"Á~,!" it will return 0. -*/ -use scores::*; - -fn main() { - println!("{}", score("a")); - println!("{}", score("ã ê Á?")); - println!("{}", score("ThiS is A Test")); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_simple() { - assert_eq!(score("a"), 1); - assert_eq!(score("A"), 1); - assert_eq!(score("h"), 4); - assert_eq!(score("at"), 2); - assert_eq!(score("Yes"), 6); - assert_eq!(score("cellphones"), 17); - } - - #[test] - fn test_empty() { - assert_eq!(score(""), 0); - assert_eq!(score(" "), 0); - } - - #[test] - fn test_special() { - assert_eq!(score("in Portugal NÃO stands for: no"), 30); - assert_eq!(score("This is a test, comparação, têm Água?"), 36); - } - - #[test] - fn test_long() { - assert_eq!(score("ThiS is A Test"), 14); - assert_eq!(score("long sentences are working"), 34); - assert_eq!(score("abcdefghijklmnopqrstuvwxyz"), 87); - } -} diff --git a/rust/tests/searching_test/Cargo.lock b/rust/tests/searching_test/Cargo.lock deleted file mode 100644 index 58bb6a4d..00000000 --- a/rust/tests/searching_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "searching" -version = "0.1.0" - -[[package]] -name = "searching_test" -version = "0.1.0" -dependencies = [ - "searching", -] diff --git a/rust/tests/searching_test/Cargo.toml b/rust/tests/searching_test/Cargo.toml deleted file mode 100644 index 74ad5bb6..00000000 --- a/rust/tests/searching_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "searching_test" -version = "0.1.0" -authors = ["MSilva95 "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -searching = { path = "../../../../rust-piscine-solutions/searching"} diff --git a/rust/tests/searching_test/src/main.rs b/rust/tests/searching_test/src/main.rs deleted file mode 100644 index 73d7d412..00000000 --- a/rust/tests/searching_test/src/main.rs +++ /dev/null @@ -1,67 +0,0 @@ -/* -## searching - -### Instructions - -In this exercise you will have to complete the function `search`. -`search` receives an array and a key of `i32`, then it will return the position -of the given key in the array. - -``` -*/ -use searching::*; - -fn main() { - let array = [1, 3, 4, 6, 8, 9, 11]; - let key = search(&array, 6); - println!( - "the element 6 is in the position {:?} in the array {:?}", - key, array - ); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_search_a_value_in_an_array() { - assert_eq!(search(&[6], 6), Some(0)); - assert_eq!(search(&[1, 2], 1), Some(0)); - assert_eq!(search(&[1, 2], 2), Some(1)); - } - #[test] - fn test_middle_of_an_array() { - assert_eq!(search(&[1, 3, 4, 6, 8, 9, 11], 6), Some(3)); - } - - #[test] - fn test_beginning_of_an_array() { - assert_eq!(search(&[1, 3, 4, 6, 8, 9, 11], 1), Some(0)); - } - - #[test] - fn test_end_of_an_array() { - assert_eq!(search(&[1, 3, 4, 6, 8, 9, 11], 11), Some(6)); - } - - #[test] - fn test_long_array() { - assert_eq!( - search(&[1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 634], 144), - Some(9) - ); - assert_eq!( - search(&[1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377], 21), - Some(5) - ); - } - - #[test] - fn test_value_is_not_included() { - assert_eq!(search(&[1, 3, 4, 6, 8, 9, 11], 7), None); - assert_eq!(search(&[1, 3, 4, 6, 8, 9, 11], 0), None); - assert_eq!(search(&[1, 3, 4, 6, 8, 9, 11], 13), None); - assert_eq!(search(&[], 1), None); - } -} diff --git a/rust/tests/simple_hash_test/Cargo.lock b/rust/tests/simple_hash_test/Cargo.lock deleted file mode 100644 index 7963380a..00000000 --- a/rust/tests/simple_hash_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "simple_hash" -version = "0.1.0" - -[[package]] -name = "simple_hash_test" -version = "0.1.0" -dependencies = [ - "simple_hash", -] diff --git a/rust/tests/simple_hash_test/Cargo.toml b/rust/tests/simple_hash_test/Cargo.toml deleted file mode 100644 index b6765339..00000000 --- a/rust/tests/simple_hash_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "simple_hash_test" -version = "0.1.0" -authors = ["MSilva95 "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -simple_hash = { path = "../../../../rust-piscine-solutions/simple_hash"} \ No newline at end of file diff --git a/rust/tests/simple_hash_test/src/main.rs b/rust/tests/simple_hash_test/src/main.rs deleted file mode 100644 index b7da3fc8..00000000 --- a/rust/tests/simple_hash_test/src/main.rs +++ /dev/null @@ -1,56 +0,0 @@ -// Create the function `contain` that checks a `HashMap` to see if it contains the given key. -// Create the function `remove` that removes a given key from the `HashMap`. - -use std::collections::HashMap; - -use simple_hash::*; - -fn main() { - let mut hash: HashMap<&str, i32> = HashMap::new(); - hash.insert("Daniel", 122); - hash.insert("Ashley", 333); - hash.insert("Katie", 334); - hash.insert("Robert", 14); - - println!( - "Does the HashMap contains the name Roman? => {}", - contain(hash.clone(), "Roman") - ); - println!( - "Does the HashMap contains the name Katie? => {}", - contain(hash.clone(), "Katie") - ); - println!("Removing Robert {:?}", remove(hash.clone(), "Robert")); - println!("Hash {:?}", hash); -} - -#[test] -fn test_contains() { - let mut s = HashMap::new(); - - s.insert("Pedro", 43); - s.insert("Ralph", 12); - s.insert("Johnny", 546); - s.insert("Albert", 12323214); - - assert_eq!(true, contain(s.clone(), "Pedro")); - assert_eq!(true, contain(s.clone(), "Ralph")); - assert_eq!(true, contain(s.clone(), "Johnny")); - assert_eq!(true, contain(s.clone(), "Albert")); - assert_eq!(false, contain(s.clone(), "Marco")); - assert_eq!(false, contain(s.clone(), "Joan")); - assert_eq!(false, contain(s.clone(), "Louise")); -} - -#[test] -fn test_remove() { - let mut n = HashMap::new(); - n.insert("Dani Sordo", 37); - n.insert("Sébastien Loeb", 46); - n.insert("Ott Tanak", 32); - n.insert("Thierry Neuville", 32); - - remove(n.clone(), "Dani Sordo"); - assert_eq!(true, contain(n.clone(), "Ott Tanak")); - assert_eq!(false, contain(n.clone(), "Dani Ŝordo")) -} diff --git a/rust/tests/slices_to_map_test/Cargo.lock b/rust/tests/slices_to_map_test/Cargo.lock deleted file mode 100644 index d0d6d626..00000000 --- a/rust/tests/slices_to_map_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "slices_to_map" -version = "0.1.0" - -[[package]] -name = "slices_to_map_test" -version = "0.1.0" -dependencies = [ - "slices_to_map", -] diff --git a/rust/tests/slices_to_map_test/Cargo.toml b/rust/tests/slices_to_map_test/Cargo.toml deleted file mode 100644 index b0328bd2..00000000 --- a/rust/tests/slices_to_map_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "slices_to_map_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -slices_to_map = { path = "../../../../rust-piscine-solutions/slices_to_map"} \ No newline at end of file diff --git a/rust/tests/slices_to_map_test/src/main.rs b/rust/tests/slices_to_map_test/src/main.rs deleted file mode 100644 index 96c9b8cc..00000000 --- a/rust/tests/slices_to_map_test/src/main.rs +++ /dev/null @@ -1,78 +0,0 @@ -// # Instructions: -// Create a function that borrows two slices (&[T]) and returns a hashmap where -// the first slice represents the keys and the second represents the values. - -// The signature of the function is the following -// fn slices_to_map<'a, T: Hash + Eq, U>(keys: &'a [T], values: &'a [U]) -> HashMap<&'a T, &'a U> { - -// # Example: -// for the slices &["hello", "how", "are", "you"] &[1, 3, 5, 8] -// returns the hashmap ["hello": 1, "how": 3, "are": 5, "you":8] - -use slices_to_map::*; -#[allow(unused_imports)] -use std::collections::HashMap; - -#[allow(dead_code)] -fn main() { - let keys = ["Olivia", "Liam", "Emma", "Noah", "James"]; - let values = [1, 3, 23, 5, 2]; - println!("{:?}", slices_to_map(&keys, &values)); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_same_length() { - let keys = ["Olivia", "Liam", "Emma", "Noah", "James"]; - let values = [1, 3, 23, 5, 2]; - let mut expected = HashMap::new(); - expected.insert(&"Olivia", &1); - expected.insert(&"Liam", &3); - expected.insert(&"Emma", &23); - expected.insert(&"Noah", &5); - expected.insert(&"James", &2); - assert_eq!(slices_to_map(&keys, &values), expected); - } - - #[test] - fn test_different_length() { - let keys = ["Olivia", "Liam", "Emma", "Noah", "James"]; - let values = [1, 3, 23, 5, 2, 9]; - let mut expected = HashMap::new(); - expected.insert(&"Olivia", &1); - expected.insert(&"Liam", &3); - expected.insert(&"Emma", &23); - expected.insert(&"Noah", &5); - expected.insert(&"James", &2); - assert_eq!(slices_to_map(&keys, &values), expected); - - let keys = ["Olivia", "Liam", "Emma", "Noah", "James", "Isabella"]; - let values = [1, 3, 23, 5, 2]; - assert_eq!(slices_to_map(&keys, &values), expected); - } - - #[test] - fn it_works_for_vecs() { - let mut expected = HashMap::new(); - expected.insert(&"Olivia", &1); - expected.insert(&"Liam", &3); - expected.insert(&"Emma", &23); - expected.insert(&"Noah", &5); - expected.insert(&"James", &2); - - let keys = ["Olivia", "Liam", "Emma", "Noah", "James"]; - let values = [1, 3, 23, 5, 2]; - - assert_eq!(slices_to_map(&keys, &values), expected); - let keys = vec!["Olivia", "Liam", "Emma", "Noah", "James"]; - let values = vec![1, 3, 23, 5, 2, 9]; - assert_eq!(slices_to_map(&keys, &values), expected); - - let keys = vec!["Olivia", "Liam", "Emma", "Noah", "James", "Isabella"]; - let values = vec![1, 3, 23, 5, 2]; - assert_eq!(slices_to_map(&keys, &values), expected); - } -} diff --git a/rust/tests/speed_transformation_test/Cargo.lock b/rust/tests/speed_transformation_test/Cargo.lock deleted file mode 100644 index 49bb77b9..00000000 --- a/rust/tests/speed_transformation_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "speed_transformation" -version = "0.1.0" - -[[package]] -name = "speed_transformation_test" -version = "0.1.0" -dependencies = [ - "speed_transformation", -] diff --git a/rust/tests/speed_transformation_test/Cargo.toml b/rust/tests/speed_transformation_test/Cargo.toml deleted file mode 100644 index 9a0a1d87..00000000 --- a/rust/tests/speed_transformation_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "speed_transformation_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -speed_transformation = { path = "../../../../rust-piscine-solutions/speed_transformation"} \ No newline at end of file diff --git a/rust/tests/speed_transformation_test/src/main.rs b/rust/tests/speed_transformation_test/src/main.rs deleted file mode 100644 index fdbb7b13..00000000 --- a/rust/tests/speed_transformation_test/src/main.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Create a function that receives the speed in km/h (kilometers per hour) and returns the -// equivalent in m/s (meters per second) - -use speed_transformation::*; - -fn main() { - let km_h = 100.0; - let m_s = km_per_hour_to_meters_per_second(km_h); - println!("{} km/h is equivalent to {} m/s", km_h, m_s); -} - -#[test] -fn kmh_to_ms() { - assert_eq!(km_per_hour_to_meters_per_second(90.0), 25.0); - assert_eq!(km_per_hour_to_meters_per_second(50.0), 13.88888888888889); - assert_eq!(km_per_hour_to_meters_per_second(10.0), 2.7777777777777777); - assert_eq!(km_per_hour_to_meters_per_second(100.0), 27.77777777777778); -} diff --git a/rust/tests/spelling_test/Cargo.lock b/rust/tests/spelling_test/Cargo.lock deleted file mode 100644 index b72287e8..00000000 --- a/rust/tests/spelling_test/Cargo.lock +++ /dev/null @@ -1,92 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[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.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "libc" -version = "0.2.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" - -[[package]] -name = "ppv-lite86" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" - -[[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 = "spelling" -version = "0.1.0" -dependencies = [ - "rand", -] - -[[package]] -name = "spelling_test" -version = "0.1.0" -dependencies = [ - "rand", - "spelling", -] - -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" diff --git a/rust/tests/spelling_test/Cargo.toml b/rust/tests/spelling_test/Cargo.toml deleted file mode 100644 index fd2fe408..00000000 --- a/rust/tests/spelling_test/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "spelling_test" -version = "0.1.0" -authors = ["MSilva95 "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -rand = "0.7" -spelling = { path = "../../../../rust-piscine-solutions/spelling"} diff --git a/rust/tests/spelling_test/src/main.rs b/rust/tests/spelling_test/src/main.rs deleted file mode 100644 index 2c864045..00000000 --- a/rust/tests/spelling_test/src/main.rs +++ /dev/null @@ -1,65 +0,0 @@ -/* -## spelling - - ### Instructions - -In this exercise a number between 0 and 1000000 will be generated. -Your purpose is to create the function `spell` that will spell the numbers generated. - -So, if the program generates the number: - -- 1 your function will return the string "one" -- 14 your function will return the string "fourteen". -- 96 your function will return the string "ninety-six" -- 100 your function will return the string "one hundred". -- 101 your function will return the string "one hundred one" -- 348 your function will return the string "one hundred twenty-three" -- 1002 your function will return the string "one thousand two". -- 1000000 your function will return the string "one million" -*/ -use spelling::*; -use rand::Rng; - -fn main() { - let mut rng = rand::thread_rng(); - println!("{}", spell(rng.gen_range(0, 1000000))); - println!("{}", spell(rng.gen_range(0, 1000000))); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_one() { - assert_eq!(spell(0), String::from("zero")); - assert_eq!(spell(1), String::from("one")); - assert_eq!(spell(14), String::from("fourteen")); - assert_eq!(spell(20), String::from("twenty")); - assert_eq!(spell(22), String::from("twenty-two")); - assert_eq!(spell(101), String::from("one hundred one")); - assert_eq!(spell(120), String::from("one hundred twenty")); - assert_eq!(spell(123), String::from("one hundred twenty-three")); - assert_eq!(spell(1000), String::from("one thousand")); - assert_eq!(spell(1055), String::from("one thousand fifty-five")); - assert_eq!( - spell(1234), - String::from("one thousand two hundred thirty-four") - ); - assert_eq!( - spell(10123), - String::from("ten thousand one hundred twenty-three") - ); - assert_eq!( - spell(910112), - String::from("nine hundred ten thousand one hundred twelve") - ); - assert_eq!( - spell(651123), - String::from("six hundred fifty-one thousand one hundred twenty-three") - ); - - assert_eq!(spell(810000), String::from("eight hundred ten thousand")); - assert_eq!(spell(1000000), String::from("one million")); - } -} diff --git a/rust/tests/stars_test/Cargo.lock b/rust/tests/stars_test/Cargo.lock deleted file mode 100644 index d78bfe40..00000000 --- a/rust/tests/stars_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "stars" -version = "0.1.0" - -[[package]] -name = "stars_test" -version = "0.1.0" -dependencies = [ - "stars", -] diff --git a/rust/tests/stars_test/Cargo.toml b/rust/tests/stars_test/Cargo.toml deleted file mode 100644 index ac7bd8a3..00000000 --- a/rust/tests/stars_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "stars_test" -version = "0.1.0" -authors = ["MSilva95 "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -stars = { path = "../../../../rust-piscine-solutions/stars"} diff --git a/rust/tests/stars_test/src/main.rs b/rust/tests/stars_test/src/main.rs deleted file mode 100644 index e621e999..00000000 --- a/rust/tests/stars_test/src/main.rs +++ /dev/null @@ -1,41 +0,0 @@ -/* -## stars - -### Instructions - -Write a recursive function named `stars` that takes an i32 as -parameter and returns a String of stars (asterisks) 2^n long (2 to the nth power). - -### Example: - -stars(0) "*" 2^0 = 1 -stars(1) "**" 2^1 = 2 -stars(2) "****" 2^2 = 4 -stars(3) "********" 2^3 = 8 -stars(4) "****************" 2^4 = 16 - -*/ -use stars::*; - -fn main() { - println!("{}", stars(4)); - println!("{}", stars(5)); -} - -#[cfg(test)] -mod test { - use super::*; - #[test] - fn test_stars() { - assert_eq!(stars(0), "*"); - assert_eq!(stars(1), "**"); - assert_eq!(stars(2), "****"); - assert_eq!(stars(3), "********"); - assert_eq!(stars(4), "****************"); - assert_eq!(stars(5), "********************************"); - assert_eq!( - stars(10), - "****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************" - ); - } -} diff --git a/rust/tests/step_iterator_test/Cargo.lock b/rust/tests/step_iterator_test/Cargo.lock deleted file mode 100644 index d6975677..00000000 --- a/rust/tests/step_iterator_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "step_iterator" -version = "0.1.0" - -[[package]] -name = "step_iterator_test" -version = "0.1.0" -dependencies = [ - "step_iterator", -] diff --git a/rust/tests/step_iterator_test/Cargo.toml b/rust/tests/step_iterator_test/Cargo.toml deleted file mode 100644 index 4d3d3f5b..00000000 --- a/rust/tests/step_iterator_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "step_iterator_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -step_iterator = { path = "../../../../rust-piscine-solutions/step_iterator"} \ No newline at end of file diff --git a/rust/tests/step_iterator_test/src/main.rs b/rust/tests/step_iterator_test/src/main.rs deleted file mode 100644 index 2599fad3..00000000 --- a/rust/tests/step_iterator_test/src/main.rs +++ /dev/null @@ -1,83 +0,0 @@ -// Create an Iterator (by implementing the std::iter::Iterator trait) -// that iterates through the values from beg to end (including end) in -// the indicated steps - -// The name of you're iterator will be StepIterator and it must be -// generic so you can use any integer value: i8,..,i64 of floating -// point number f32,..,f64 - -// Define the associated function: `new` that creates a new Step iterator: -// fn new(beg: T, end: T, step: T) -> StepIterator - -// For example: -// for v in StepIterator::new(0, 100, 10) { -// println!("{}", v); -// } -// must print: -// 0 -// 10 -// 20 -// 30 -// 40 -// 50 -// 60 -// 70 -// 80 -// 90 -// 100 - -// If the steps don't allow to arrive until the end of the sequence -// only the last value inferior than the end of the series will be returned -// Like beg: 0, end: 100, steps: 7 the last number returned will be -// the last number returned will be 98 - -use step_iterator::StepIterator; - -#[allow(dead_code)] -fn main() { - for v in StepIterator::new(0, 100, 10) { - print!("{},", v); - } - println!(); - - for v in StepIterator::new(0, 100, 12) { - print!("{},", v) - } - println!(); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_next() { - let mut step_iterator = StepIterator::new(0, 100, 10); - assert_eq!(step_iterator.next(), Some(0)); - assert_eq!(step_iterator.next(), Some(10)); - } - - #[test] - fn until_the_end() { - for (i, v) in StepIterator::new(0, 100, 10).enumerate() { - println!("position: {}, value: {}, ", i, v); - assert_eq!(i * 10, v); - } - } - - #[test] - fn test_with_floats() { - for (i, v) in StepIterator::new(0.0, 10.0, 0.5).enumerate() { - println!("position: {}, value: {}, ", i, v); - assert_eq!(i as f64 * 0.5, v); - } - } - - #[test] - fn test_with_floats_with_imperfect_range() { - for (i, v) in StepIterator::new(0.3, 10.0, 0.5).enumerate() { - println!("position: {}, value: {}, ", i, v); - assert_eq!(i as f64 * 0.5 + 0.3, v); - } - } -} diff --git a/rust/tests/string_literal_test/Cargo.lock b/rust/tests/string_literal_test/Cargo.lock deleted file mode 100644 index ab001602..00000000 --- a/rust/tests/string_literal_test/Cargo.lock +++ /dev/null @@ -1,93 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[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" - -[[package]] -name = "string_literal" -version = "0.1.0" -dependencies = [ - "jemalloc-ctl", - "jemallocator", -] - -[[package]] -name = "string_literal_test" -version = "0.1.0" -dependencies = [ - "jemalloc-ctl", - "jemallocator", - "string_literal", -] diff --git a/rust/tests/string_literal_test/Cargo.toml b/rust/tests/string_literal_test/Cargo.toml deleted file mode 100644 index b06ef391..00000000 --- a/rust/tests/string_literal_test/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "string_literal_test" -version = "0.1.0" -authors = ["lee "] -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" -string_literal = { path = "../../../../rust-piscine-solutions/string_literal"} diff --git a/rust/tests/string_literal_test/src/main.rs b/rust/tests/string_literal_test/src/main.rs deleted file mode 100644 index 933f5d33..00000000 --- a/rust/tests/string_literal_test/src/main.rs +++ /dev/null @@ -1,107 +0,0 @@ -/* -## string literal - -### Instructions - -Create the following functions: - -- `is_empty`, that returns true if a string is empty -- `is_ascii`, that returns true if all characters of a given string is in ASCII range -- `contains`, that returns true if the string contains a pattern given -- `split_at`, that divides a string in two returning a tuple -- `find', that returns the index if the first character of a given string that matches the pattern - -> This exercise will test the **heap allocation** of your function! -> So try your best to allocate the minimum data on the heap! (hit: &str) - -### Notions - -- https://doc.rust-lang.org/1.22.0/book/first-edition/the-stack-and-the-heap.html -- https://doc.rust-lang.org/rust-by-example/primitives/literals.html - -*/ - -#[global_allocator] -static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; - -#[allow(unused_imports)] -use jemalloc_ctl::{epoch, stats}; -#[allow(unused_imports)] -use string_literal::*; - -#[allow(dead_code)] -fn is_empty_sol(v: &str) -> bool { - v.is_empty() -} - -#[allow(dead_code)] -fn is_ascii_sol(v: &str) -> bool { - v.is_ascii() -} - -#[allow(dead_code)] -fn contains_sol(v: &str, pat: &str) -> bool { - v.contains(pat) -} - -#[allow(dead_code)] -fn split_at_sol(v: &str, index: usize) -> (&str, &str) { - v.split_at(index) -} - -#[allow(dead_code)] -fn find_sol(v: &str, pat: char) -> usize { - v.find(pat).unwrap() -} - -#[test] -fn test_memory() { - // 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(); - - // sense we only use string literals (&str) - // the heap will not be allocated, because - // &str are preallocated text (saved on the binary file) - is_empty_sol(""); - is_ascii_sol("rust"); - contains_sol("rust", "ru"); - split_at_sol("rust", 2); - find_sol("rust", 'u'); - // 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(); - - is_empty(""); - is_ascii_sol("rust"); - contains("rust", "er"); - split_at("rust", 2); - find("rust", 'u'); - - 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_functions() { - assert!(is_empty("")); - assert!(!is_empty("something")); - assert!(is_ascii("rust")); - assert!(!is_ascii("rust¬")); - assert!(contains("rust", "ru")); - assert!(!contains("something", "mer")); - assert_eq!(split_at("rust", 2), ("ru", "st")); - assert_eq!(find("ru-st-e", '-'), 2); - assert_eq!(find("ru-st-e", 'e'), 6); -} diff --git a/rust/tests/string_permutation_test/Cargo.lock b/rust/tests/string_permutation_test/Cargo.lock deleted file mode 100644 index 490d5b7f..00000000 --- a/rust/tests/string_permutation_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "string_permutation" -version = "0.1.0" - -[[package]] -name = "string_permutation_test" -version = "0.1.0" -dependencies = [ - "string_permutation", -] diff --git a/rust/tests/string_permutation_test/Cargo.toml b/rust/tests/string_permutation_test/Cargo.toml deleted file mode 100644 index 2f2fc560..00000000 --- a/rust/tests/string_permutation_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "string_permutation_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -string_permutation = { path = "../../../../rust-piscine-solutions/string_permutation"} \ No newline at end of file diff --git a/rust/tests/string_permutation_test/src/main.rs b/rust/tests/string_permutation_test/src/main.rs deleted file mode 100644 index 38329915..00000000 --- a/rust/tests/string_permutation_test/src/main.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Define the function `is_permutation` that returns true if the -// string `s1` is a permutation of `s2`, otherwise it returns false -// `s1` is a permutation of `s2` if all the elements in `s1` appear the -// same number of times in `s2` and all the characters in `s1` appear in -// `s2` even if in different order) -use string_permutation::*; - -#[allow(dead_code)] -fn main() { - let word = "thought"; - let word1 = "thougth"; - println!( - "Is `{}` a permutation of `{}`? = {}", - word, - word1, - is_permutation(word, word1) - ); -} - -#[test] -fn permutation_ascii() { - assert!(is_permutation("abcde", "edbca")); - assert!(!is_permutation("avcde", "edbca")); - assert!(!is_permutation("cde", "edbca")); - assert!(is_permutation("code", "deco")); - assert!(!is_permutation("code", "deeco")); - assert!(!is_permutation("codde", "deeco")); -} - -#[test] -fn permutation_unicode() { - assert!(is_permutation("hello♥", "♥oelhl")); - assert!(!is_permutation("♥", "♥♥")); -} diff --git a/rust/tests/strings_test/Cargo.lock b/rust/tests/strings_test/Cargo.lock deleted file mode 100644 index 2c288afa..00000000 --- a/rust/tests/strings_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "strings" -version = "0.1.0" - -[[package]] -name = "strings_test" -version = "0.1.0" -dependencies = [ - "strings", -] diff --git a/rust/tests/strings_test/Cargo.toml b/rust/tests/strings_test/Cargo.toml deleted file mode 100644 index 0cefe153..00000000 --- a/rust/tests/strings_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "strings_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -strings = { path = "../../../../rust-piscine-solutions/strings"} \ No newline at end of file diff --git a/rust/tests/strings_test/src/main.rs b/rust/tests/strings_test/src/main.rs deleted file mode 100644 index 25b8099b..00000000 --- a/rust/tests/strings_test/src/main.rs +++ /dev/null @@ -1,39 +0,0 @@ -// Write a function that receives a string slice and returns the -// length of character of the string - -use strings::*; - -fn main() { - println!("lenght of {} = {}", "❤", "❤".len()); - println!("lenght of {} = {}", "❤", char_lenght("❤")); - println!("lenght of {} = {}", "形声字", char_lenght("形聲字")); - println!("lenght of {} = {}", "形声字", "形聲字".len()); - println!("lenght of {} = {}", "change", "change".len()); - println!("lenght of {} = {}", "change", char_lenght("change")); - println!("char lenght of {} = {}", "😍", char_lenght("😍")); -} - -// fn char_lenght(s: &str) -> usize { -// let mut chars = 0; -// for _ in s.chars() { -// chars += 1; -// } -// chars -// } - -#[test] -fn test_ascii() { - let s = "ascii"; - assert_eq!(char_lenght(s), 5); -} - -#[test] -fn test_emoji() { - let s = "❤😍"; - assert_eq!(char_lenght(s), 2); -} -#[test] -fn test_chinese_char() { - let s = "形声字"; - assert_eq!(char_lenght(s), 3); -} diff --git a/rust/tests/talking_test/Cargo.lock b/rust/tests/talking_test/Cargo.lock deleted file mode 100644 index 15623495..00000000 --- a/rust/tests/talking_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "talking" -version = "0.1.0" - -[[package]] -name = "talking_test" -version = "0.1.0" -dependencies = [ - "talking", -] diff --git a/rust/tests/talking_test/Cargo.toml b/rust/tests/talking_test/Cargo.toml deleted file mode 100644 index 32fbc845..00000000 --- a/rust/tests/talking_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "talking_test" -version = "0.1.0" -authors = ["MSilva95 "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -talking = { path = "../../../../rust-piscine-solutions/talking"} diff --git a/rust/tests/talking_test/src/main.rs b/rust/tests/talking_test/src/main.rs deleted file mode 100644 index a5b3bd72..00000000 --- a/rust/tests/talking_test/src/main.rs +++ /dev/null @@ -1,83 +0,0 @@ -/* -## talking - -### Instructions - -Build the function `talking` that will allow you to talk with your computer. -His answers will be created by you following the rules below. - -He answers "There is no need to yell, calm down!" if you yell at him, for example "LEAVE ME ALONE!" -(it is consider yelling when the sentence is all written in capital letters). -He answers "Sure" if you ask him something without yelling, for example "Is everything ok with you?" -He answers "Quiet, I am thinking!" if you yell a question at him. "HOW ARE YOU?" -He says "Just say something!" if you address him without actually saying anything. -He answers "Interesting" to anything else. - -*/ -use talking::*; -fn main() { - println!("{:?}", talking("JUST DO IT!")); - println!("{:?}", talking("Hello how are you?")); - println!("{:?}", talking("WHAT'S GOING ON?")); - println!("{:?}", talking("something")); - println!("{:?}", talking("")); -} - -#[cfg(test)] -mod tests { - use super::*; - #[test] - fn test_yell() { - assert_eq!( - talking("JUST DO IT!"), - "There is no need to yell, calm down!" - ); - assert_eq!( - talking("1, 2, 3 GO!"), - "There is no need to yell, calm down!" - ); - assert_eq!( - talking("I LOVE YELLING"), - "There is no need to yell, calm down!" - ); - assert_eq!( - talking("WJDAGSAF ASVF EVA VA"), - "There is no need to yell, calm down!" - ); - } - - #[test] - fn test_question() { - assert_eq!(talking("Hello how are you?"), "Sure."); - assert_eq!(talking("Are you going to be OK?"), "Sure."); - assert_eq!(talking("7?"), "Sure."); - assert_eq!(talking("Like 15?"), "Sure."); - } - - #[test] - fn test_question_yelling() { - assert_eq!(talking("WHAT'S GOING ON?"), "Quiet, I am thinking!"); - assert_eq!( - talking("ARE YOU FINISHED?"), - "Quiet, I am thinking!" - ); - assert_eq!(talking("WHAT DID I DO?"), "Quiet, I am thinking!"); - assert_eq!(talking("ARE YOU COMING?"), "Quiet, I am thinking!"); - } - - #[test] - fn test_interesting() { - assert_eq!(talking("something"), "Interesting"); - assert_eq!(talking("Wow that's good!"), "Interesting"); - assert_eq!(talking("Run far"), "Interesting"); - assert_eq!(talking("1 2 3 go!"), "Interesting"); - assert_eq!(talking("This is not ? a question."), "Interesting"); - } - - #[test] - fn test_empty() { - assert_eq!(talking(""), "Just say something!"); - assert_eq!(talking(" "), "Just say something!"); - assert_eq!(talking(" "), "Just say something!"); - } -} diff --git a/rust/tests/temperature_conv_test/Cargo.lock b/rust/tests/temperature_conv_test/Cargo.lock deleted file mode 100644 index 60474937..00000000 --- a/rust/tests/temperature_conv_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "temperature_conv" -version = "0.1.0" - -[[package]] -name = "temperature_conv_test" -version = "0.1.0" -dependencies = [ - "temperature_conv", -] diff --git a/rust/tests/temperature_conv_test/Cargo.toml b/rust/tests/temperature_conv_test/Cargo.toml deleted file mode 100644 index 892c2cab..00000000 --- a/rust/tests/temperature_conv_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "temperature_conv_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -temperature_conv = { path = "../../../../rust-piscine-solutions/temperature_conv"} diff --git a/rust/tests/temperature_conv_test/src/main.rs b/rust/tests/temperature_conv_test/src/main.rs deleted file mode 100644 index 134a532a..00000000 --- a/rust/tests/temperature_conv_test/src/main.rs +++ /dev/null @@ -1,27 +0,0 @@ -use temperature_conv::*; - -use std::f64::EPSILON; - -fn eql(a: f64, b: f64) -> bool { - (b - a).abs() < EPSILON -} - -#[test] -fn test_f_to_c() { - let temp_f = 20.0; - println!("{}°F = {}°C", temp_f, fahrenheit_to_celsius(temp_f)); - assert!(eql(fahrenheit_to_celsius(temp_f), -6.666666666666666)); - let temp_f = 83.0; - println!("{}°F = {}°C", temp_f, fahrenheit_to_celsius(temp_f)); - assert!(eql(fahrenheit_to_celsius(temp_f), 28.333333333333332)); -} - -#[test] -fn test_c_to_f() { - let temp_c = 27.0; - println!("{}°C = {}°F", temp_c, fahrenheit_to_celsius(temp_c)); - assert!(eql(celsius_to_fahrenheit(27.0), 80.6)); - let temp_c = 0.0; - println!("{}°C = {}°F", temp_c, fahrenheit_to_celsius(temp_c)); - assert!(eql(celsius_to_fahrenheit(temp_c), 32.0)) -} diff --git a/rust/tests/tic_tac_toe_test/Cargo.lock b/rust/tests/tic_tac_toe_test/Cargo.lock deleted file mode 100644 index fea0ff94..00000000 --- a/rust/tests/tic_tac_toe_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "tic_tac_toe" -version = "0.1.0" - -[[package]] -name = "tic_tac_toe_test" -version = "0.1.0" -dependencies = [ - "tic_tac_toe", -] diff --git a/rust/tests/tic_tac_toe_test/Cargo.toml b/rust/tests/tic_tac_toe_test/Cargo.toml deleted file mode 100644 index aed3f26a..00000000 --- a/rust/tests/tic_tac_toe_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "tic_tac_toe_test" -version = "0.1.0" -authors = ["lee "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -tic_tac_toe = { path = "../../../../rust-piscine-solutions/tic_tac_toe"} \ No newline at end of file diff --git a/rust/tests/tic_tac_toe_test/src/main.rs b/rust/tests/tic_tac_toe_test/src/main.rs deleted file mode 100644 index a63a3515..00000000 --- a/rust/tests/tic_tac_toe_test/src/main.rs +++ /dev/null @@ -1,340 +0,0 @@ -/* -## tic_tac_toe - -### Instructions - -You must create a tic tac toe checker. - -Create the following functions: - -- `tic_tac_toe` that receives a table of vectors (Vec>) and returns a string : `player O won` or `player X won` or `Tie` -- `diagonals` that will receive a player and a table. It should return a boolean, this must return true if all the diagonals are completed by the player -- `horizontal` that will receive a player and a table. It should return a boolean, this must return true if one of the horizontal lines are completed by the player -- `vertical` that will receive a player and a table. It should return a boolean, this must return true if one of the vertical lines are completed by the player - -### Example - - -``` - -### Notions - -- https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html - -*/ - -// fn check(player: &str, table: &Vec>) -> bool { -// diagonals(player, &table) || horizontal(player, &table) || vertical(player, &table) -// } - -// fn tic_tac_toe(table: Vec>) -> String { -// let player1 = "X"; -// let player2 = "O"; -// if check(player2, &table) { -// return format!("player {} won", player2); -// } else if check(player1, &table) { -// return format!("player {} won", player1); -// } else { -// return "Tie".to_string(); -// } -// } - -// fn diagonals(player: &str, table: &Vec>) -> bool { -// let mut count = 0; -// let mut count_inv = 0; -// for (i, v) in table.iter().enumerate() { -// if v.get(i).unwrap() == &player { -// count += 1; -// } -// if v.get((table.len() - 1) - i).unwrap() == &player { -// count_inv += 1; -// } -// } -// return count == table.len() || count_inv == table.len(); -// } - -// // not good will change the solution -// fn horizontal(player: &str, table: &Vec>) -> bool { -// let mut count = 0; -// for v in table.iter() { -// for value in v.iter() { -// if value == &player { -// count += 1 -// } -// } -// if count == table.len() { -// return true; -// } -// count = 0; -// } -// return false; -// } - -// // not good will change the solution -// fn vertical(player: &str, table: &Vec>) -> bool { -// let mut count = 0; -// for (i, _) in table.iter().enumerate() { -// for v in table.iter() { -// if v.get(i).unwrap() == &player { -// count += 1; -// } -// } -// if count == table.len() { -// return true; -// } -// count = 0; -// } -// return false; -// } -use tic_tac_toe::*; - -fn main() { - println!( - "{:?}", - tic_tac_toe(vec![ - vec!["O", "X", "O"], - vec!["O", "P", "X"], - vec!["X", "#", "X"] - ]) - ); - // "Tie" - println!( - "{:?}", - tic_tac_toe(vec![ - vec!["X", "O", "O"], - vec!["X", "O", "O"], - vec!["#", "O", "X"] - ]) - ); - // "player O won" - - let dig = vec![ - vec!["O", "O", "X"], - vec!["O", "X", "O"], - vec!["X", "#", "X"], - ]; - - println!("{:?}", tic_tac_toe(dig)); - // "player X won" -} -#[cfg(test)] -mod tests { - use super::*; - - struct Test<'a> { - player: &'a str, - table: Vec>, - result: &'a str, - } - - impl Test<'_> { - fn init_horizontal() -> Vec> { - vec![ - Test { - player: "O", - table: vec![ - vec!["O", "O", "O"], - vec!["X", "X", "O"], - vec!["O", "#", "X"], - ], - result: "player O won", - }, - Test { - player: "O", - table: vec![ - vec!["X", "X", "O"], - vec!["O", "O", "O"], - vec!["O", "#", "X"], - ], - result: "player O won", - }, - Test { - player: "X", - table: vec![ - vec!["O", "X", "O"], - vec!["O", "#", "O"], - vec!["X", "X", "X"], - ], - result: "player X won", - }, - Test { - player: "X", - table: vec![ - vec!["O", "X", "O", "O"], - vec!["X", "X", "X", "X"], - vec!["X", "#", "O", "X"], - vec!["X", "X", "O", "O"], - ], - result: "player X won", - }, - ] - } - fn init_tie() -> Vec> { - vec![ - Test { - player: "none", - table: vec![ - vec!["O", "X", "O"], - vec!["O", "X", "O"], - vec!["X", "#", "X"], - ], - result: "Tie", - }, - Test { - player: "none", - table: vec![ - vec!["O", "X", "O"], - vec!["X", "X", "O"], - vec!["X", "#", "X"], - ], - result: "Tie", - }, - Test { - player: "none", - table: vec![ - vec!["O", "X", "O", "O"], - vec!["X", "O", "X", "X"], - vec!["X", "#", "X", "X"], - vec!["X", "X", "O", "O"], - ], - result: "Tie", - }, - ] - } - fn init_vertical() -> Vec> { - vec![ - Test { - player: "O", - table: vec![ - vec!["O", "X", "O"], - vec!["O", "X", "O"], - vec!["O", "#", "X"], - ], - result: "player O won", - }, - Test { - player: "O", - table: vec![ - vec!["X", "O", "O"], - vec!["X", "O", "O"], - vec!["#", "O", "X"], - ], - result: "player O won", - }, - Test { - player: "X", - table: vec![ - vec!["O", "X", "X"], - vec!["O", "X", "X"], - vec!["X", "#", "X"], - ], - result: "player X won", - }, - ] - } - fn init_diagonals() -> Vec> { - vec![ - Test { - player: "X", - table: vec![ - vec!["O", "O", "X"], - vec!["O", "X", "O"], - vec!["X", "#", "X"], - ], - result: "player X won", - }, - Test { - player: "O", - table: vec![ - vec!["O", "X", "O"], - vec!["X", "O", "O"], - vec!["X", "#", "O"], - ], - result: "player O won", - }, - Test { - player: "O", - table: vec![ - vec!["O", "X", "O", "O"], - vec!["X", "O", "X", "O"], - vec!["X", "#", "O", "X"], - vec!["X", "X", "O", "O"], - ], - result: "player O won", - }, - ] - } - } - - #[test] - fn test_diagonals() { - let new_tests = Test::init_diagonals(); - for v in new_tests { - assert_eq!(diagonals(v.player, &v.table), true) - } - - assert_eq!( - diagonals( - "O", - &vec![ - vec!["O", "X", "X"], - vec!["O", "X", "X"], - vec!["X", "#", "X"] - ] - ), - false - ); - } - - #[test] - fn test_horizontal() { - let new_tests = Test::init_horizontal(); - for v in new_tests { - assert_eq!(horizontal(v.player, &v.table), true) - } - - assert_eq!( - horizontal( - "O", - &vec![ - vec!["O", "X", "X"], - vec!["O", "O", "X"], - vec!["X", "#", "O"] - ] - ), - false - ); - } - - #[test] - fn test_vertical() { - let new_tests = Test::init_vertical(); - for v in new_tests { - assert_eq!(vertical(v.player, &v.table), true) - } - - assert_eq!( - vertical( - "O", - &vec![ - vec!["O", "X", "X"], - vec!["O", "O", "X"], - vec!["X", "#", "O"] - ] - ), - false - ); - } - - #[test] - fn test_tic_tac_toe() { - let mut new_tests = Test::init_diagonals(); - new_tests.append(&mut Test::init_horizontal()); - new_tests.append(&mut Test::init_vertical()); - new_tests.append(&mut Test::init_tie()); - - for v in new_tests { - assert_eq!(tic_tac_toe(v.table), v.result.to_string()); - } - } -} diff --git a/rust/tests/to_url_test/Cargo.lock b/rust/tests/to_url_test/Cargo.lock deleted file mode 100644 index ebff1fcd..00000000 --- a/rust/tests/to_url_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "to_url" -version = "0.1.0" - -[[package]] -name = "to_url_test" -version = "0.1.0" -dependencies = [ - "to_url", -] diff --git a/rust/tests/to_url_test/Cargo.toml b/rust/tests/to_url_test/Cargo.toml deleted file mode 100644 index ec78b00f..00000000 --- a/rust/tests/to_url_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "to_url_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -to_url = { path = "../../../../rust-piscine-solutions/to_url"} \ No newline at end of file diff --git a/rust/tests/to_url_test/src/main.rs b/rust/tests/to_url_test/src/main.rs deleted file mode 100644 index c9ee018c..00000000 --- a/rust/tests/to_url_test/src/main.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Define a function called `to_url` that takes a string and -// substitutes every white-space with '%20' - -use to_url::*; - -fn main() { - let s = "Hello, world!"; - println!("{} to be use as an url is {}", s, to_url(s)); -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_url() { - assert_eq!(to_url("this is my search"), "this%20is%20my%20search"); - } -} diff --git a/rust/tests/traits_test/Cargo.lock b/rust/tests/traits_test/Cargo.lock deleted file mode 100644 index 3e0e5745..00000000 --- a/rust/tests/traits_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "traits" -version = "0.1.0" - -[[package]] -name = "traits_test" -version = "0.1.0" -dependencies = [ - "traits", -] diff --git a/rust/tests/traits_test/Cargo.toml b/rust/tests/traits_test/Cargo.toml deleted file mode 100644 index 690edcb6..00000000 --- a/rust/tests/traits_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "traits_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -traits = { path = "../../../../rust-piscine-solutions/traits"} \ No newline at end of file diff --git a/rust/tests/traits_test/src/main.rs b/rust/tests/traits_test/src/main.rs deleted file mode 100644 index 8eee2da9..00000000 --- a/rust/tests/traits_test/src/main.rs +++ /dev/null @@ -1,67 +0,0 @@ -// Imagine you are designing a new video game and you have to create -// food that they players can take to gain strength there are two -// types of food for now fruits and meet: fruits increases the -// strengths by 1 unit and meat increases it by 3 unit. - -// Define both structures fruits and meat -// Define the std::fmt::Display trait of the Player structure so using -// the template {} inside a println! macro will print in the first -// line the name of the player -// in the second line the strength, score and the money -// and in the third line the weapons -use traits::{Food, Fruit, Meat, Player}; - -fn main() { - let apple = Fruit { weight_in_kg: 1.0 }; - assert_eq!(apple.gives(), 4); - let steak = Meat { - weight_in_kg: 1.0, - fat_content: 1.0, - }; - - let mut player1 = Player { - name: String::from("player1"), - strength: 1, - score: 0, - money: 0, - weapons: vec![String::from("knife")], - }; - println!("Before eating {:?}", player1); - player1.eat(apple); - println!("After eating an apple\n{:?}", player1); - player1.eat(steak); - println!("After eating a steak\n{:?}", player1); -} - -#[test] -fn test_gives() { - let apple = Fruit { weight_in_kg: 1.0 }; - assert_eq!(apple.gives(), 4); - let steak = Meat { - weight_in_kg: 1.0, - fat_content: 1.0, - }; - assert_eq!(steak.gives(), 9); -} - -#[test] -fn test_eat() { - let apple = Fruit { weight_in_kg: 1.0 }; - assert_eq!(apple.gives(), 4); - let steak = Meat { - weight_in_kg: 1.0, - fat_content: 1.0, - }; - - let mut player1 = Player { - name: String::from("player1"), - strength: 1, - score: 0, - money: 0, - weapons: vec![String::from("knife")], - }; - player1.eat(apple); - assert_eq!(player1.strength, 5); - player1.eat(steak); - assert_eq!(player1.strength, 14); -} diff --git a/rust/tests/tuples_test/Cargo.lock b/rust/tests/tuples_test/Cargo.lock deleted file mode 100644 index 4ef8e206..00000000 --- a/rust/tests/tuples_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "tuples" -version = "0.1.0" - -[[package]] -name = "tuples_test" -version = "0.1.0" -dependencies = [ - "tuples", -] diff --git a/rust/tests/tuples_test/Cargo.toml b/rust/tests/tuples_test/Cargo.toml deleted file mode 100644 index 6939cef1..00000000 --- a/rust/tests/tuples_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "tuples_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -tuples = { path = "../../../../rust-piscine-solutions/tuples"} \ No newline at end of file diff --git a/rust/tests/tuples_test/src/main.rs b/rust/tests/tuples_test/src/main.rs deleted file mode 100644 index 0e0810bb..00000000 --- a/rust/tests/tuples_test/src/main.rs +++ /dev/null @@ -1,35 +0,0 @@ -// Define a tuple to represent a student -// Each student is identified by an id number of type i32 -// Its name and its last name as a string -// Print the content of the tuple to stdout - -use tuples::*; - -fn main() { - let student = Student(20, "Pedro".to_string(), "Domingos".to_string()); - println!("Student: {:?}", student); - // After print only the first name - println!("Student first name: {}", first_name(&student)); - // After print only the last name - println!("Student last name: {}", last_name(&student)); - // After print only the id - println!("Student Id: {}", id(&student)); -} - -#[test] -fn test_id() { - let student = Student(20, String::from("Pedro"), String::from("Domingos")); - assert_eq!(id(&student), 20); -} - -#[test] -fn test_first_name() { - let student = Student(20, String::from("Pedro"), String::from("Domingos")); - assert_eq!(first_name(&student), "Pedro".to_string()); -} - -#[test] -fn test_last_name() { - let student = Student(20, String::from("Pedro"), String::from("Domingos")); - assert_eq!(last_name(&student), "Domingos".to_string()); -} diff --git a/rust/tests/unwrap_and_expect_test/Cargo.lock b/rust/tests/unwrap_and_expect_test/Cargo.lock deleted file mode 100644 index a263be69..00000000 --- a/rust/tests/unwrap_and_expect_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "unwrap_and_expect" -version = "0.1.0" - -[[package]] -name = "unwrap_and_expect_test" -version = "0.1.0" -dependencies = [ - "unwrap_and_expect", -] diff --git a/rust/tests/unwrap_and_expect_test/Cargo.toml b/rust/tests/unwrap_and_expect_test/Cargo.toml deleted file mode 100644 index 05c2b114..00000000 --- a/rust/tests/unwrap_and_expect_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "unwrap_and_expect_test" -version = "0.1.0" -authors = ["lee "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -unwrap_and_expect = { path = "../../../../rust-piscine-solutions/unwrap_and_expect"} diff --git a/rust/tests/unwrap_and_expect_test/src/main.rs b/rust/tests/unwrap_and_expect_test/src/main.rs deleted file mode 100644 index 894679a3..00000000 --- a/rust/tests/unwrap_and_expect_test/src/main.rs +++ /dev/null @@ -1,49 +0,0 @@ -use unwrap_and_expect::*; - -fn main() { - println!("{:?}", unwrap_or(vec![1, 3, 2, 5])); - println!("{:?}", unwrap_or(vec![1, 3, 5])); - println!("{:?}", unwrap_err(vec![1, 3, 2, 5])); - println!("{:?}", unwrap(vec![1, 3, 5])); - println!("{:?}", unwrap_or_else(vec![1, 3, 5])); - println!("{:?}", unwrap_or_else(vec![3, 2, 6, 5])); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - #[should_panic(expected = "ERROR : (\"There is a even value in the vector!\", [2])")] - fn test_expect() { - expect(vec![1, 3, 2, 5]); - } - #[test] - #[should_panic(expected = "called `Result::unwrap()` on an `Err` value: (\"There is a even value in the vector!\", [2])")] - fn test_unwrap() { - unwrap(vec![1, 3, 2, 5]); - } - #[test] - #[should_panic] - fn test_unwrap_err() { - unwrap_err(vec![1, 3, 5]); - } - #[test] - fn test_unwrap_or() { - assert_eq!(unwrap_or(vec![1, 3, 2, 5]), vec![]); - } - #[test] - fn test_unwrap_or_else() { - assert_eq!(unwrap_or_else(vec![1, 3, 5]), vec![2, 4, 6]); - assert_eq!(unwrap_or_else(vec![6, 8, 3, 2, 5, 4]), vec![6, 8, 2, 4]); - } - #[test] - fn test_ok() { - assert_eq!(expect(vec![1, 3, 5]), vec![2, 4, 6]); - assert_eq!(unwrap_or(vec![1, 3, 5]), vec![2, 4, 6]); - assert_eq!(unwrap_or_else(vec![1, 3, 5]), vec![2, 4, 6]); - assert_eq!(unwrap(vec![1, 3, 5]), vec![2, 4, 6]); - assert_eq!(unwrap_err(vec![1, 2, 3, 4, 5]).0, "There is a even value in the vector!"); - assert_eq!(unwrap_err(vec![1, 2, 3, 4, 5]).1, vec![2, 4]); - } -} diff --git a/rust/tests/vector_operations_test/Cargo.lock b/rust/tests/vector_operations_test/Cargo.lock deleted file mode 100644 index 7c0461ff..00000000 --- a/rust/tests/vector_operations_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "vector_operations" -version = "0.1.0" - -[[package]] -name = "vector_operations_test" -version = "0.1.0" -dependencies = [ - "vector_operations", -] diff --git a/rust/tests/vector_operations_test/Cargo.toml b/rust/tests/vector_operations_test/Cargo.toml deleted file mode 100644 index 65bbce2f..00000000 --- a/rust/tests/vector_operations_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "vector_operations_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -vector_operations = { path = "../../../../rust-piscine-solutions/vector_operations"} \ No newline at end of file diff --git a/rust/tests/vector_operations_test/src/main.rs b/rust/tests/vector_operations_test/src/main.rs deleted file mode 100644 index 2082d936..00000000 --- a/rust/tests/vector_operations_test/src/main.rs +++ /dev/null @@ -1,40 +0,0 @@ -// Define the structures ThreeDvector that represents a 3 dimensional -// vector in (for convention in physics the vector are represented as -// ai + bj + ck where a, b, and c are real numbers and i, j and k -// represent the direction x,y and z respectively in the Cartesian plane -// there for we use the names i, j and k for the fields in the -// ThreeDVector structure - -// Look how the operations Addition and Subtraction work for a 3 -// dimensional vector and implement them by implementing the -// std::ops::Add and std::ops::Sub traits - -use vector_operations::ThreeDVector; - -#[allow(dead_code)] -fn main() { - let a = ThreeDVector { i: 3, j: 5, k: 2 }; - let b = ThreeDVector { i: 2, j: 7, k: 4 }; - println!("{:?}", a + b); -} - -#[test] -fn it_works() { - assert_eq!(2 + 2, 4); -} - -#[test] -fn test_addition() { - let a = ThreeDVector { i: 3, j: 5, k: 2 }; - let b = ThreeDVector { i: 2, j: 7, k: 4 }; - let a_plus_b = ThreeDVector { i: 5, j: 12, k: 6 }; - assert_eq!(a + b, a_plus_b); -} - -#[test] -fn test_subtraction() { - let a = ThreeDVector { i: 3, j: 5, k: 2 }; - let b = ThreeDVector { i: 2, j: 7, k: 4 }; - let a_minus_b = ThreeDVector { i: 1, j: -2, k: -2 }; - assert_eq!(a - b, a_minus_b); -} diff --git a/rust/tests/vehicles_test/Cargo.lock b/rust/tests/vehicles_test/Cargo.lock deleted file mode 100644 index 2c20105d..00000000 --- a/rust/tests/vehicles_test/Cargo.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "vehicles" -version = "0.1.0" - -[[package]] -name = "vehicles_test" -version = "0.1.0" -dependencies = [ - "vehicles", -] diff --git a/rust/tests/vehicles_test/Cargo.toml b/rust/tests/vehicles_test/Cargo.toml deleted file mode 100644 index ce81189e..00000000 --- a/rust/tests/vehicles_test/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "vehicles_test" -version = "0.1.0" -authors = ["Augusto "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -vehicles = { path = "../../../../rust-piscine-solutions/vehicles"} diff --git a/rust/tests/vehicles_test/src/main.rs b/rust/tests/vehicles_test/src/main.rs deleted file mode 100644 index 6c31114d..00000000 --- a/rust/tests/vehicles_test/src/main.rs +++ /dev/null @@ -1,131 +0,0 @@ -// Create the trait Vehicle with the model and year - -// In a border cross you want to keep a list of all the vehicles that -// are waiting to enter the country. You want to keep a waiting list -// of the vehicle but the vehicles can be of two types: Car or Truck -// With the following structure: - -// create a function that receives a vector of structures that -// implement the Vehicle trait - -use vehicles::{all_models, Car, Truck, Vehicle}; - -#[allow(dead_code)] -fn main() { - let vehicles: Vec<&dyn Vehicle> = vec![ - &Car { - plate_nbr: "A3D5C7", - model: "Model 3", - horse_power: 325, - year: 2010, - }, - &Truck { - plate_nbr: "V3D5CT", - model: "Ranger", - horse_power: 325, - year: 2010, - load_tons: 40, - }, - ]; - println!("{:?}", all_models(vehicles)); -} - -#[allow(dead_code)] -fn setup_cars<'a>() -> Vec<&'a dyn Vehicle> { - let cars: Vec<&dyn Vehicle> = vec![ - &Car { - plate_nbr: "A3D5C7", - model: "Model 3", - horse_power: 325, - year: 2010, - }, - &Car { - plate_nbr: "A785P7", - model: "S", - horse_power: 500, - year: 1980, - }, - &Car { - plate_nbr: "D325C7", - model: "300", - horse_power: 300, - year: 2000, - }, - &Car { - plate_nbr: "Z3KCH4", - model: "Montana", - horse_power: 325, - year: 2020, - }, - ]; - cars -} - -#[allow(dead_code)] -fn setup_trucks<'a>() -> Vec<&'a dyn Vehicle> { - let trucks: Vec<&dyn Vehicle> = vec![ - &Truck { - plate_nbr: "V3D5CT", - model: "Ranger", - horse_power: 325, - year: 2010, - load_tons: 40, - }, - &Truck { - plate_nbr: "V785PT", - model: "Silverado", - horse_power: 500, - year: 1980, - load_tons: 40, - }, - &Truck { - plate_nbr: "DE2SC7", - model: "Sierra", - horse_power: 300, - year: 2000, - load_tons: 40, - }, - &Truck { - plate_nbr: "3DH432", - model: "Cybertruck", - horse_power: 325, - year: 2020, - load_tons: 40, - }, - ]; - trucks -} - -#[test] -fn all_car_models() { - let cars = setup_cars(); - assert_eq!(all_models(cars), ["Model 3", "S", "300", "Montana"]); -} - -#[test] -fn all_truck_models() { - let trucks = setup_trucks(); - assert_eq!( - all_models(trucks), - ["Ranger", "Silverado", "Sierra", "Cybertruck"] - ); -} - -#[test] -fn cars_and_trucks_models() { - let mut vehicles = setup_cars(); - vehicles.extend(setup_trucks()); - assert_eq!( - all_models(vehicles), - [ - "Model 3", - "S", - "300", - "Montana", - "Ranger", - "Silverado", - "Sierra", - "Cybertruck" - ] - ); -}