diff --git a/rust/tests/string_permutation_test/Cargo.lock b/rust/tests/string_permutation_test/Cargo.lock new file mode 100644 index 000000000..490d5b7fb --- /dev/null +++ b/rust/tests/string_permutation_test/Cargo.lock @@ -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", +] diff --git a/rust/tests/string_permutation_test/Cargo.toml b/rust/tests/string_permutation_test/Cargo.toml new file mode 100644 index 000000000..2f2fc560e --- /dev/null +++ b/rust/tests/string_permutation_test/Cargo.toml @@ -0,0 +1,10 @@ +[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 new file mode 100644 index 000000000..383299150 --- /dev/null +++ b/rust/tests/string_permutation_test/src/main.rs @@ -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("♥", "♥♥")); +} diff --git a/subjects/string_permutation/README.md b/subjects/string_permutation/README.md new file mode 100644 index 000000000..d33f0222a --- /dev/null +++ b/subjects/string_permutation/README.md @@ -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$ +```