|
|
|
@ -1,5 +1,5 @@ |
|
|
|
use super::encoder::{Encoder, Rule, Rules}; |
|
|
|
use super::decoder::{Decoder, Rule, Rules}; |
|
|
|
use crate::core::traits::SystemEncoder; |
|
|
|
use crate::core::traits::SystemDecoder; |
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)] |
|
|
|
#[cfg(test)] |
|
|
|
mod tests { |
|
|
|
mod tests { |
|
|
|
@ -44,91 +44,91 @@ mod tests { |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_single_symbol_encoding_only_before_only_after_matched() { |
|
|
|
fn test_single_symbol_encoding_only_before_only_after_matched() { |
|
|
|
let encoder = Encoder::new(create_single_rules()); |
|
|
|
let decoder = Decoder::new(create_single_rules()); |
|
|
|
let output = encoder.encode("ABC"); |
|
|
|
let output = decoder.decode("ABC"); |
|
|
|
assert_eq!(output, "2") |
|
|
|
assert_eq!(output, "2") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_double_symbol_encoding_only_before_only_after_matched() { |
|
|
|
fn test_double_symbol_encoding_only_before_only_after_matched() { |
|
|
|
let encoder = Encoder::new(create_double_rules()); |
|
|
|
let decoder = Decoder::new(create_double_rules()); |
|
|
|
let output = encoder.encode("ABCDEF"); |
|
|
|
let output = decoder.decode("ABCDEF"); |
|
|
|
assert_eq!(output, "2") |
|
|
|
assert_eq!(output, "2") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_single_symbol_encoding_only_before_not_matched_with_other() { |
|
|
|
fn test_single_symbol_encoding_only_before_not_matched_with_other() { |
|
|
|
let encoder = Encoder::new(create_single_rules()); |
|
|
|
let decoder = Decoder::new(create_single_rules()); |
|
|
|
let output = encoder.encode("DBC"); |
|
|
|
let output = decoder.decode("DBC"); |
|
|
|
assert_eq!(output, "") |
|
|
|
assert_eq!(output, "") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_double_symbol_encoding_only_before_not_matched_with_other() { |
|
|
|
fn test_double_symbol_encoding_only_before_not_matched_with_other() { |
|
|
|
let encoder = Encoder::new(create_double_rules()); |
|
|
|
let decoder = Decoder::new(create_double_rules()); |
|
|
|
let output = encoder.encode("AACDEE"); |
|
|
|
let output = decoder.decode("AACDEE"); |
|
|
|
assert_eq!(output, "") |
|
|
|
assert_eq!(output, "") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_case_insensitivity() { |
|
|
|
fn test_case_insensitivity() { |
|
|
|
let encoder = Encoder::new(create_double_rules()); |
|
|
|
let decoder = Decoder::new(create_double_rules()); |
|
|
|
let output = encoder.encode("abcdef"); |
|
|
|
let output = decoder.decode("abcdef"); |
|
|
|
assert_eq!(output, "2") |
|
|
|
assert_eq!(output, "2") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_single_symbol_encoding_only_before_not_matched_with_empty() { |
|
|
|
fn test_single_symbol_encoding_only_before_not_matched_with_empty() { |
|
|
|
let encoder = Encoder::new(create_single_rules()); |
|
|
|
let decoder = Decoder::new(create_single_rules()); |
|
|
|
let output = encoder.encode("BC"); |
|
|
|
let output = decoder.decode("BC"); |
|
|
|
assert_eq!(output, "") |
|
|
|
assert_eq!(output, "") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_single_symbol_encoding_only_before_not_matched_with_not_before() { |
|
|
|
fn test_single_symbol_encoding_only_before_not_matched_with_not_before() { |
|
|
|
let encoder = Encoder::new(create_single_rules()); |
|
|
|
let decoder = Decoder::new(create_single_rules()); |
|
|
|
let output = encoder.encode("XBC"); |
|
|
|
let output = decoder.decode("XBC"); |
|
|
|
assert_eq!(output, "") |
|
|
|
assert_eq!(output, "") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_single_symbol_encoding_only_after_not_matched_with_other() { |
|
|
|
fn test_single_symbol_encoding_only_after_not_matched_with_other() { |
|
|
|
let encoder = Encoder::new(create_single_rules()); |
|
|
|
let decoder = Decoder::new(create_single_rules()); |
|
|
|
let output = encoder.encode("ABD"); |
|
|
|
let output = decoder.decode("ABD"); |
|
|
|
assert_eq!(output, "") |
|
|
|
assert_eq!(output, "") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_single_symbol_encoding_only_after_not_matched_with_empty() { |
|
|
|
fn test_single_symbol_encoding_only_after_not_matched_with_empty() { |
|
|
|
let encoder = Encoder::new(create_single_rules()); |
|
|
|
let decoder = Decoder::new(create_single_rules()); |
|
|
|
let output = encoder.encode("AB"); |
|
|
|
let output = decoder.decode("AB"); |
|
|
|
assert_eq!(output, "") |
|
|
|
assert_eq!(output, "") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_single_symbol_encoding_only_after_not_matched_with_not_after() { |
|
|
|
fn test_single_symbol_encoding_only_after_not_matched_with_not_after() { |
|
|
|
let encoder = Encoder::new(create_single_rules()); |
|
|
|
let decoder = Decoder::new(create_single_rules()); |
|
|
|
let output = encoder.encode("ABY"); |
|
|
|
let output = decoder.decode("ABY"); |
|
|
|
assert_eq!(output, "") |
|
|
|
assert_eq!(output, "") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_single_symbol_encoding_empty_before_after_matched_with_empty() { |
|
|
|
fn test_single_symbol_encoding_empty_before_after_matched_with_empty() { |
|
|
|
let encoder = Encoder::new(create_single_rules_min()); |
|
|
|
let decoder = Decoder::new(create_single_rules_min()); |
|
|
|
let output = encoder.encode("B"); |
|
|
|
let output = decoder.decode("B"); |
|
|
|
assert_eq!(output, "2") |
|
|
|
assert_eq!(output, "2") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_single_symbol_encoding_empty_before_after_matched_with_others() { |
|
|
|
fn test_single_symbol_encoding_empty_before_after_matched_with_others() { |
|
|
|
let encoder = Encoder::new(create_single_rules_min()); |
|
|
|
let decoder = Decoder::new(create_single_rules_min()); |
|
|
|
let output = encoder.encode("AXBYC"); |
|
|
|
let output = decoder.decode("AXBYC"); |
|
|
|
assert_eq!(output, "2") |
|
|
|
assert_eq!(output, "2") |
|
|
|
} |
|
|
|
} |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_encoding_multiple_phonemes() { |
|
|
|
fn test_encoding_multiple_phonemes() { |
|
|
|
let encoder = Encoder::new(create_double_rules()); |
|
|
|
let decoder = Decoder::new(create_double_rules()); |
|
|
|
let output = encoder.encode("VvmNabCd33mn00CD22cdefmn"); |
|
|
|
let output = decoder.decode("VvmNabCd33mn00CD22cdefmn"); |
|
|
|
assert_eq!(output, "32323") |
|
|
|
assert_eq!(output, "32323") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |