-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
pub struct Solution; | ||
|
||
impl Solution { | ||
pub fn to_lower_case(s: String) -> String { | ||
s.to_lowercase() | ||
} | ||
} | ||
|
||
impl super::Solution for Solution { | ||
fn to_lower_case(str: String) -> String { | ||
Self::to_lower_case(str) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn test_solution() { | ||
super::super::tests::run::<super::Solution>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
pub struct Solution; | ||
|
||
impl Solution { | ||
pub fn to_lower_case(s: String) -> String { | ||
let mut s = s.into_bytes(); | ||
for ch in &mut s { | ||
if *ch >= b'A' && *ch <= b'Z' { | ||
*ch = *ch - b'A' + b'a'; | ||
} | ||
} | ||
String::from_utf8(s).unwrap() | ||
} | ||
} | ||
|
||
impl super::Solution for Solution { | ||
fn to_lower_case(str: String) -> String { | ||
Self::to_lower_case(str) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn test_solution() { | ||
super::super::tests::run::<super::Solution>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
pub mod cheating; | ||
pub mod iterative; | ||
|
||
pub trait Solution { | ||
fn to_lower_case(str: String) -> String; | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::Solution; | ||
|
||
pub fn run<S: Solution>() { | ||
let test_cases = [("Hello", "hello"), ("here", "here"), ("LOVELY", "lovely")]; | ||
|
||
for (str, expected) in test_cases { | ||
assert_eq!(S::to_lower_case(str.to_string()), expected); | ||
} | ||
} | ||
} |