Skip to content

Commit

Permalink
Added alphanumeric solution
Browse files Browse the repository at this point in the history
  • Loading branch information
jusexton committed Jul 28, 2023
1 parent 4fd3a84 commit 7bded63
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ other languages.
- Diamond (https://www.codewars.com/kata/5503013e34137eeeaa001648)
- Fibonacci Product (https://www.codewars.com/kata/5541f58a944b85ce6d00006a)
- Valid Parentheses (https://www.codewars.com/kata/52774a314c2333f0a7000688)
- Alphanumeric (https://www.codewars.com/kata/526dbd6c8c0eb53254000110)

#### Kata 6

Expand Down
1 change: 1 addition & 0 deletions src/codewars/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ mod camel_case;
mod cats_and_shelves;
mod people_on_the_bus;
mod summation;
mod not_secure;
38 changes: 38 additions & 0 deletions src/codewars/not_secure.rs
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);
}
}

0 comments on commit 7bded63

Please sign in to comment.