fn verify_sum(name_one: &str, name_two: &str) -> bool { sum(name_one) == sum(name_two) } fn sum(name: &str) -> u32 { name.chars() .filter(|ch| ch.is_ascii_alphabetic()) .map(u32::from) .sum() }
- fn verify_sum(name_one: &str, name_two: &str) -> bool {
- sum(name_one) == sum(name_two)
- }
- fn sum(name: &str) -> u32 {
- name.chars()
- .filter(|ch| ch.is_ascii_alphabetic())
.map(|ch| ch as u32)- .map(u32::from)
- .sum()
- }
#[cfg(test)] mod test { use super::*; #[test] fn test() { assert!(!verify_sum("Sebastian", "Patricia")); assert!(verify_sum("Anna", "Nana")); assert!(verify_sum("","")); assert!(verify_sum("John Doe", "Doe John")); assert!(verify_sum("Bob", "bOb")); } }
- #[cfg(test)]
- mod test {
- use super::*;
- #[test]
- fn test() {
- assert!(!verify_sum("Sebastian", "Patricia"));
- assert!(verify_sum("Anna", "Nana"));
- assert!(verify_sum("",""));
- assert!(verify_sum("John Doe", "Doe John"));
- assert!(verify_sum("Bob", "bOb"));
- }
- }