-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://exercism.org/tracks/rust/exercises/isogram
- Loading branch information
Showing
3 changed files
with
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[package] | ||
edition = "2021" | ||
name = "isogram" | ||
version = "1.3.0" |
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,8 @@ | ||
use std::collections::HashSet; | ||
|
||
|
||
pub fn check(candidate: &str) -> bool { | ||
let lowercase_str = candidate.chars().filter(|c| c.is_alphabetic()).into_iter().collect::<String>().to_lowercase(); | ||
let s: HashSet<char> = HashSet::from_iter(lowercase_str.chars()); | ||
lowercase_str.len() == s.len() | ||
} |
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,67 @@ | ||
use isogram::check; | ||
|
||
#[test] | ||
fn empty_string() { | ||
assert!(check(""), "An empty string should be an isogram.") | ||
} | ||
|
||
#[test] | ||
fn only_lower_case_characters() { | ||
assert!(check("isogram"), "\"isogram\" should be an isogram.") | ||
} | ||
|
||
#[test] | ||
fn one_duplicated_character() { | ||
assert!( | ||
!check("eleven"), | ||
"\"eleven\" has more than one \'e\', therefore it is no isogram." | ||
) | ||
} | ||
|
||
#[test] | ||
fn longest_reported_english_isogram() { | ||
assert!( | ||
check("subdermatoglyphic"), | ||
"\"subdermatoglyphic\" should be an isogram." | ||
) | ||
} | ||
|
||
#[test] | ||
fn one_duplicated_character_mixed_case() { | ||
assert!( | ||
!check("Alphabet"), | ||
"\"Alphabet\" has more than one \'a\', therefore it is no isogram." | ||
) | ||
} | ||
|
||
#[test] | ||
fn hypothetical_isogramic_word_with_hyphen() { | ||
assert!( | ||
check("thumbscrew-japingly"), | ||
"\"thumbscrew-japingly\" should be an isogram." | ||
) | ||
} | ||
|
||
#[test] | ||
fn isogram_with_duplicated_hyphen() { | ||
assert!( | ||
check("six-year-old"), | ||
"\"six-year-old\" should be an isogram." | ||
) | ||
} | ||
|
||
#[test] | ||
fn made_up_name_that_is_an_isogram() { | ||
assert!( | ||
check("Emily Jung Schwartzkopf"), | ||
"\"Emily Jung Schwartzkopf\" should be an isogram." | ||
) | ||
} | ||
|
||
#[test] | ||
fn duplicated_character_in_the_middle() { | ||
assert!( | ||
!check("accentor"), | ||
"\"accentor\" has more than one \'c\', therefore it is no isogram." | ||
) | ||
} |