mirror of https://github.com/01-edu/public.git
Augusto
4 years ago
4 changed files with 178 additions and 0 deletions
@ -0,0 +1,91 @@
|
||||
# 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" |
@ -0,0 +1,10 @@
|
||||
[package] |
||||
name = "bigger_test" |
||||
version = "0.1.0" |
||||
authors = ["MSilva95 <miguel-silva98@hotmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
bigger = { path = "../../../../rust-piscine-solutions/bigger"} |
@ -0,0 +1,39 @@
|
||||
// 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)); |
||||
} |
@ -0,0 +1,38 @@
|
||||
## bigger |
||||
|
||||
### Instructions |
||||
|
||||
Create the function `bigger` that gets the biggest positive number in the `HashMap`. |
||||
|
||||
### Expected Function |
||||
|
||||
```rust |
||||
fn bigger(h: HashMap<&str, i32>) -> i32 { |
||||
} |
||||
``` |
||||
|
||||
### Usage |
||||
|
||||
Here is a program to test your function. |
||||
|
||||
```rust |
||||
use bigger::bigger; |
||||
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)); |
||||
} |
||||
``` |
||||
|
||||
And its output |
||||
|
||||
```console |
||||
student@ubuntu:~/[[ROOT]]/test$ cargo run |
||||
Is `thought` a permutation of `thougth`? = true |
||||
student@ubuntu:~/[[ROOT]]/test$ |
||||
``` |
Loading…
Reference in new issue