Browse Source

Add the subject and test of `string_permutation`

pull/692/head
Augusto 4 years ago
parent
commit
39b6310b68
  1. 12
      rust/tests/string_permutation_test/Cargo.lock
  2. 10
      rust/tests/string_permutation_test/Cargo.toml
  3. 34
      rust/tests/string_permutation_test/src/main.rs
  4. 37
      subjects/string_permutation/README.md

12
rust/tests/string_permutation_test/Cargo.lock diff.generated

@ -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",
]

10
rust/tests/string_permutation_test/Cargo.toml

@ -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"}

34
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("♥", "♥♥"));
}

37
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$
```
Loading…
Cancel
Save