Skip to content

Commit

Permalink
another codewars solution
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmir17 committed Jun 8, 2024
1 parent ab2d788 commit ac2c221
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions codewars_kata_training/examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,39 @@ mod array_diff_tests {
}
}


#[cfg(test)]
mod duplicate_counter_tests {
use std::collections::HashMap;

fn count_duplicates(text: &str) -> u32 {
let mut char_count = HashMap::new();

for c in text.to_lowercase().chars() {
if c.is_alphanumeric() {
*char_count.entry(c).or_insert(0) += 1;
}
}

char_count.values().filter(|&count| *count > 1).count() as u32
}

#[test]
fn test_abcde() {
assert_eq!(count_duplicates("abcde"), 0);
}

#[test]
fn test_abcdea() {
assert_eq!(count_duplicates("abcdea"), 1);
}

#[test]
fn test_indivisibility() {
assert_eq!(count_duplicates("indivisibility"), 1);
}
}

#[cfg(test)]
mod break_camelcase_tests {
fn solution(s: &str) -> String {
Expand Down

0 comments on commit ac2c221

Please sign in to comment.