Browse Source

Add subject and test for the exercise `capitalizing`

content-update
Augusto 3 years ago
parent
commit
22344890c5
  1. 12
      rust/tests/capitalizing_test/Cargo.lock
  2. 10
      rust/tests/capitalizing_test/Cargo.toml
  3. 38
      rust/tests/capitalizing_test/src/main.rs
  4. 44
      subjects/capitalizing/README.md

12
rust/tests/capitalizing_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 = "capitalizing"
version = "0.1.0"
[[package]]
name = "capitalizing_test"
version = "0.1.0"
dependencies = [
"capitalizing",
]

10
rust/tests/capitalizing_test/Cargo.toml

@ -0,0 +1,10 @@
[package]
name = "capitalizing_test"
version = "0.1.0"
authors = ["MSilva95 <miguel-silva98@hotmail.com>"]
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"}

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

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