Skip to content

Commit

Permalink
https://exercism.org/tracks/rust/exercises/isogram
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunjun committed Feb 28, 2024
1 parent 1c23454 commit b9fdcc3
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rust/isogram/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
edition = "2021"
name = "isogram"
version = "1.3.0"
8 changes: 8 additions & 0 deletions rust/isogram/src/lib.rs
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()
}
67 changes: 67 additions & 0 deletions rust/isogram/tests/isogram.rs
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."
)
}

0 comments on commit b9fdcc3

Please sign in to comment.