-
Notifications
You must be signed in to change notification settings - Fork 4
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
3 changed files
with
40 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 |
---|---|---|
|
@@ -43,3 +43,4 @@ mod camel_case; | |
mod cats_and_shelves; | ||
mod people_on_the_bus; | ||
mod summation; | ||
mod not_secure; |
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,38 @@ | ||
// Regex solution | ||
// use regex::Regex; | ||
// | ||
// fn alphanumeric(password: &str) -> bool { | ||
// let regex = Regex::new("^[a-zA-Z0-9]+$").unwrap(); | ||
// regex.is_match(password) | ||
// } | ||
|
||
fn alphanumeric(password: &str) -> bool { | ||
!password.is_empty() && password.chars().all(char::is_alphanumeric) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use test_case::test_case; | ||
|
||
use crate::codewars::not_secure::alphanumeric; | ||
|
||
#[test] | ||
fn should_return_false_when_value_is_empty() { | ||
let actual = alphanumeric(""); | ||
assert_eq!(actual, false); | ||
} | ||
|
||
#[test_case("hello", true)] | ||
#[test_case("PassW0rd", true)] | ||
fn should_return_true_when_value_is_alphanumeric(value: &str, expected: bool) { | ||
let actual = alphanumeric(value); | ||
assert_eq!(actual, expected); | ||
} | ||
|
||
#[test_case("hello world_", false)] | ||
#[test_case(" ", false)] | ||
fn should_return_false_when_value_is_not_alphanumeric(value: &str, expected: bool) { | ||
let actual = alphanumeric(value); | ||
assert_eq!(actual, expected); | ||
} | ||
} |