From 22344890c5cfaafdfa155c4d010fff287c4d56dd Mon Sep 17 00:00:00 2001 From: Augusto Date: Sun, 27 Dec 2020 15:28:23 +0000 Subject: [PATCH] Add subject and test for the exercise `capitalizing` --- rust/tests/capitalizing_test/Cargo.lock | 12 +++++++ rust/tests/capitalizing_test/Cargo.toml | 10 ++++++ rust/tests/capitalizing_test/src/main.rs | 38 ++++++++++++++++++++ subjects/capitalizing/README.md | 44 ++++++++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 rust/tests/capitalizing_test/Cargo.lock create mode 100644 rust/tests/capitalizing_test/Cargo.toml create mode 100644 rust/tests/capitalizing_test/src/main.rs create mode 100644 subjects/capitalizing/README.md diff --git a/rust/tests/capitalizing_test/Cargo.lock b/rust/tests/capitalizing_test/Cargo.lock new file mode 100644 index 000000000..3d340e3fd --- /dev/null +++ b/rust/tests/capitalizing_test/Cargo.lock @@ -0,0 +1,12 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "capitalizing" +version = "0.1.0" + +[[package]] +name = "capitalizing_test" +version = "0.1.0" +dependencies = [ + "capitalizing", +] diff --git a/rust/tests/capitalizing_test/Cargo.toml b/rust/tests/capitalizing_test/Cargo.toml new file mode 100644 index 000000000..92782bcf6 --- /dev/null +++ b/rust/tests/capitalizing_test/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "capitalizing_test" +version = "0.1.0" +authors = ["MSilva95 "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +capitalizing = { path = "../../../../rust-piscine-solutions/capitalizing"} diff --git a/rust/tests/capitalizing_test/src/main.rs b/rust/tests/capitalizing_test/src/main.rs new file mode 100644 index 000000000..cf20b84b5 --- /dev/null +++ b/rust/tests/capitalizing_test/src/main.rs @@ -0,0 +1,38 @@ +// Complete the `capitalize_first` function that turns the first letter of a string uppercase. +// Complete the `title_case` function that turns the first letter of each word in a string uppercase. +// Complete the `change_case` function that turns the uppercase letters of a string into lowercase and +// the lowercase letters into uppercase. + +use capitalizing::*; + +#[allow(dead_code)] +fn main() { + println!("{}", capitalize_first("joe is missing")); + println!("{}", title_case("jill is leaving A")); + println!("{}", change_case("heLLo THere")); +} + +#[test] +fn test_success() { + assert_eq!(capitalize_first("hello"), "Hello"); + assert_eq!(capitalize_first("this is working"), "This is working"); +} + +#[test] +fn test_titlle_case() { + assert_eq!(title_case("this is a tittle"), "This Is A Tittle"); + assert_eq!(title_case("hello my name is carl"), "Hello My Name Is Carl"); +} + +#[test] +fn test_change_case() { + assert_eq!(change_case("PROgraming"), "proGRAMING"); + assert_eq!(change_case("heLLo THere"), "HEllO thERE"); +} + +#[test] +fn test_empty() { + assert_eq!(capitalize_first(""), ""); + assert_eq!(title_case(""), ""); + assert_eq!(change_case(""), ""); +} diff --git a/subjects/capitalizing/README.md b/subjects/capitalizing/README.md new file mode 100644 index 000000000..4490c1dd2 --- /dev/null +++ b/subjects/capitalizing/README.md @@ -0,0 +1,44 @@ +## capitalizing + +### Instructions + +Complete the `capitalize_first` function that turns the first letter of a string uppercase. + +Complete the `title_case` function that turns the first letter of each word in a string uppercase. + +Complete the `change_case` function that turns the uppercase letters of a string into lowercase and the lowercase letters into uppercase. + +### Expected Functions + +```rust +pub fn capitalize_first(input: &str) -> String { +} + +pub fn title_case(input: &str) -> String { +} + +pub fn change_case(input: &str) -> String { +} +``` + +### Usage + +Here is a program to test your function. + +```rust +fn main() { + println!("{}", capitalize_first("joe is missing")); + println!("{}", title_case("jill is leaving A")); + println!("{}",change_case("heLLo THere")); +} +``` + +And its output + +```console +student@ubuntu:~/[[ROOT]]/test$ cargo run +Joe is missing +Jill Is Leaving A +HEllO thERE +student@ubuntu:~/[[ROOT]]/test$ +```