forked from root/public
Augusto
4 years ago
4 changed files with 97 additions and 0 deletions
@ -0,0 +1,12 @@ |
|||||||
|
# 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" |
@ -0,0 +1,10 @@ |
|||||||
|
[package] |
||||||
|
name = "reverse-string_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] |
||||||
|
reverse_string = { path = "../../../../rust-piscine-solutions/reverse_string"} |
@ -0,0 +1,39 @@ |
|||||||
|
// Write a function `rev_str` that takes a `&str` as a parameter, and returns a string with its words reversed.
|
||||||
|
|
||||||
|
#[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")); |
||||||
|
} |
||||||
|
|
||||||
|
use reverse_string::rev_str; |
||||||
|
|
||||||
|
#[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"); |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
## reverse_string |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function `rev_str` that takes a `&str` as a parameter, and returns a string with its words reversed. |
||||||
|
|
||||||
|
### Expected Functions |
||||||
|
|
||||||
|
```rust |
||||||
|
pub fn rev_str(input: &str) -> String { |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
```rust |
||||||
|
use reverse_string::rev_str; |
||||||
|
|
||||||
|
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")); |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And it's output: |
||||||
|
|
||||||
|
```console |
||||||
|
!dlrow ,olleH |
||||||
|
namoR si eman ym ,olleH |
||||||
|
!rac ecin a evah I |
||||||
|
uoY era dlo woH |
||||||
|
augá elpmaxe na si siht :xe |
||||||
|
``` |
Loading…
Reference in new issue