use crate::core::major::*; use crate::core::traits::SystemEncoder; #[cfg(test)] mod tests { use super::*; fn create_single_dict() -> Dict { vec![DictEntry { phoneme_in: "B".to_string(), phoneme_out: "2".to_string(), not_after: vec!["Y".to_string()], not_before: vec!["X".to_string()], only_after: vec!["A".to_string()], only_before: vec!["C".to_string()], }] } fn create_single_dict_min() -> Dict { vec![DictEntry { phoneme_in: "B".to_string(), phoneme_out: "2".to_string(), ..Default::default() }] } fn create_double_dict() -> Dict { vec![DictEntry { phoneme_in: "CD".to_string(), phoneme_out: "2".to_string(), not_after: vec!["YZ".to_string()], not_before: vec!["WX".to_string()], only_after: vec!["AB".to_string()], only_before: vec!["EF".to_string()], }] } #[test] fn test_single_symbol_encoding_only_before_only_after_matched() { let encoder = Encoder::new(create_single_dict()); let output = encoder.encode("ABC"); assert_eq!(output, "2") } #[test] fn test_double_symbol_encoding_only_before_only_after_matched() { let encoder = Encoder::new(create_double_dict()); let output = encoder.encode("ABCDEF"); assert_eq!(output, "2") } #[test] fn test_single_symbol_encoding_only_before_not_matched_with_other() { let encoder = Encoder::new(create_single_dict()); let output = encoder.encode("DBC"); assert_eq!(output, "") } #[test] fn test_double_symbol_encoding_only_before_not_matched_with_other() { let encoder = Encoder::new(create_double_dict()); let output = encoder.encode("AACDEE"); assert_eq!(output, "") } #[test] fn test_case_insensitivity() { let encoder = Encoder::new(create_double_dict()); let output = encoder.encode("abcdef"); assert_eq!(output, "2") } #[test] fn test_single_symbol_encoding_only_before_not_matched_with_empty() { let encoder = Encoder::new(create_single_dict()); let output = encoder.encode("BC"); assert_eq!(output, "") } #[test] fn test_single_symbol_encoding_only_before_not_matched_with_not_before() { let encoder = Encoder::new(create_single_dict()); let output = encoder.encode("XBC"); assert_eq!(output, "") } #[test] fn test_single_symbol_encoding_only_after_not_matched_with_other() { let encoder = Encoder::new(create_single_dict()); let output = encoder.encode("ABD"); assert_eq!(output, "") } #[test] fn test_single_symbol_encoding_only_after_not_matched_with_empty() { let encoder = Encoder::new(create_single_dict()); let output = encoder.encode("AB"); assert_eq!(output, "") } #[test] fn test_single_symbol_encoding_only_after_not_matched_with_not_after() { let encoder = Encoder::new(create_single_dict()); let output = encoder.encode("ABY"); assert_eq!(output, "") } #[test] fn test_single_symbol_encoding_empty_before_after_matched_with_empty() { let encoder = Encoder::new(create_single_dict_min()); let output = encoder.encode("B"); assert_eq!(output, "2") } #[test] fn test_single_symbol_encoding_empty_before_after_matched_with_others() { let encoder = Encoder::new(create_single_dict_min()); let output = encoder.encode("AXBYC"); assert_eq!(output, "2") } }