From 39b6310b689cc917cf15306475e8fa2e7cf515e6 Mon Sep 17 00:00:00 2001 From: Augusto Date: Sun, 27 Dec 2020 17:19:11 +0000 Subject: [PATCH] Add the subject and test of `string_permutation` --- rust/tests/string_permutation_test/Cargo.lock | 12 ++++++ rust/tests/string_permutation_test/Cargo.toml | 10 +++++ .../tests/string_permutation_test/src/main.rs | 34 +++++++++++++++++ subjects/string_permutation/README.md | 37 +++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 rust/tests/string_permutation_test/Cargo.lock create mode 100644 rust/tests/string_permutation_test/Cargo.toml create mode 100644 rust/tests/string_permutation_test/src/main.rs create mode 100644 subjects/string_permutation/README.md diff --git a/rust/tests/string_permutation_test/Cargo.lock b/rust/tests/string_permutation_test/Cargo.lock new file mode 100644 index 00000000..490d5b7f --- /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 00000000..2f2fc560 --- /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 00000000..38329915 --- /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 00000000..d33f0222 --- /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$ +```