Browse Source

Add test and subjects of exercise `delete_prefix`

content-update
Augusto 3 years ago
parent
commit
8d01419a79
  1. 12
      rust/tests/delete_prefix_test/Cargo.lock
  2. 10
      rust/tests/delete_prefix_test/Cargo.toml
  3. 32
      rust/tests/delete_prefix_test/src/main.rs
  4. 32
      subjects/delete_prefix/README.md

12
rust/tests/delete_prefix_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 = "delete_prefix"
version = "0.1.0"
[[package]]
name = "delete_prefix_test"
version = "0.1.0"
dependencies = [
"delete_prefix",
]

10
rust/tests/delete_prefix_test/Cargo.toml

@ -0,0 +1,10 @@
[package]
name = "delete_prefix_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]
delete_prefix = { path = "../../../../rust-piscine-solutions/delete_prefix"}

32
rust/tests/delete_prefix_test/src/main.rs

@ -0,0 +1,32 @@
// Define the function `delete_prefix(prefix: &str, s: &str) -> Option<&str>`
// That takes 2 slices of string and returns the string of slice s
// with the `prefix` removed wrapped in Some
// If `prefix ` is not contained in `s` return None
// Example:
// delete_prefix("hello, ", "hello, world")? == "world"
// delete_prefix("not", "win");
use delete_prefix::*;
#[allow(dead_code)]
fn main() {
println!("{:?}", delete_prefix("ab", "abcdefghijklmnop"));
println!("{:?}", delete_prefix("x", "abcdefghijklmnop"));
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_delete_prefix() {
assert_eq!(delete_prefix("john", "john wick"), Some(" wick"));
assert_eq!(delete_prefix("ab", "b"), None);
assert_eq!(delete_prefix("aa", "ab"), None);
assert_eq!(delete_prefix("á©", "á©ab"), Some("ab"));
}
}

32
subjects/delete_prefix/README.md

@ -0,0 +1,32 @@
## delete_prefix
### Instructions
Define the function `delete_prefix(prefix, s)` that returns the string slice `s` with the `prefix` removed wrapped in Some. If `prefix ` is not contained in `s` return None
### Expected Function
```rust
fn delete_prefix(prefix: &str, s: &str) -> Option<&str> {
}
```
### Usage
Here is a program to test your function.
```rust
fn main() {
println!("{:?}", delete_prefix("ab", "abcdefghijklmnop"));
println!("{:?}", delete_prefix("x", "abcdefghijklmnop"));
}
```
And its output
```console
student@ubuntu:~/[[ROOT]]/test$ cargo run
Some("cdefghijklmnop")
None
student@ubuntu:~/[[ROOT]]/test$
```
Loading…
Cancel
Save