mirror of https://github.com/01-edu/public.git
Augusto
4 years ago
4 changed files with 93 additions and 0 deletions
@ -0,0 +1,12 @@ |
|||||||
|
# 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", |
||||||
|
] |
@ -0,0 +1,10 @@ |
|||||||
|
[package] |
||||||
|
name = "string_permutation_test" |
||||||
|
version = "0.1.0" |
||||||
|
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||||
|
edition = "2018" |
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||||
|
|
||||||
|
[dependencies] |
||||||
|
string_permutation = { path = "../../../../rust-piscine-solutions/string_permutation"} |
@ -0,0 +1,34 @@ |
|||||||
|
// 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("♥", "♥♥")); |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
## string_permutation |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
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) |
||||||
|
|
||||||
|
### Expected Function |
||||||
|
|
||||||
|
```rust |
||||||
|
fn is_permutation(s1: &str, s2: &str) -> bool { |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a program to test your function. |
||||||
|
|
||||||
|
```rust |
||||||
|
fn main() { |
||||||
|
let word = "thought"; |
||||||
|
let word1 = "thougth"; |
||||||
|
println!( |
||||||
|
"Is `{}` a permutation of `{}`? = {}", |
||||||
|
word, |
||||||
|
word1, |
||||||
|
is_permutation(word, word1) |
||||||
|
); |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
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