use super::*;
#[test]
fn test_academic_profile_thresholds() {
let profile = crate::config::ExtractionProfile::for_document_type(crate::config::DocumentType::Academic);
assert!(
profile.tj_offset_threshold < -100.0,
"Academic should use lower TJ threshold for more spaces"
);
assert!(
profile.word_margin_ratio <= 0.15,
"Academic should use conservative word margin"
);
let config = TextExtractionConfig::with_space_threshold(profile.tj_offset_threshold);
assert_eq!(config.space_insertion_threshold, profile.tj_offset_threshold);
}
#[test]
fn test_policy_profile_thresholds() {
let profile = crate::config::ExtractionProfile::for_document_type(crate::config::DocumentType::Policy);
assert!(
profile.tj_offset_threshold > -120.0,
"Policy should use higher TJ threshold to avoid over-spacing"
);
assert!(
profile.word_margin_ratio >= 0.15,
"Policy should use higher word margin for justified text"
);
let config = TextExtractionConfig::with_space_threshold(profile.tj_offset_threshold);
assert_eq!(config.space_insertion_threshold, profile.tj_offset_threshold);
}
#[test]
fn test_form_profile_thresholds() {
let profile = crate::config::ExtractionProfile::for_document_type(crate::config::DocumentType::Form);
assert!(
profile.tj_offset_threshold >= -120.0,
"Form profile should be conservative with space insertion"
);
let config = TextExtractionConfig::with_space_threshold(profile.tj_offset_threshold);
assert_eq!(config.space_insertion_threshold, profile.tj_offset_threshold);
}
#[test]
fn test_profile_selection_for_document_types() {
let academic = crate::config::ExtractionProfile::for_document_type(crate::config::DocumentType::Academic);
let policy = crate::config::ExtractionProfile::for_document_type(crate::config::DocumentType::Policy);
let form = crate::config::ExtractionProfile::for_document_type(crate::config::DocumentType::Form);
let mixed = crate::config::ExtractionProfile::for_document_type(crate::config::DocumentType::Mixed);
let thresholds = [
academic.tj_offset_threshold,
policy.tj_offset_threshold,
form.tj_offset_threshold,
mixed.tj_offset_threshold,
];
let unique_count = thresholds
.iter()
.filter(|t| !thresholds.iter().skip(1).any(|other| other == *t))
.count();
assert!(
unique_count > 0,
"Profiles should have different thresholds for different document types"
);
}
#[test]
fn test_config_with_profile() {
let profile = crate::config::ExtractionProfile::ACADEMIC;
let config = TextExtractionConfig::with_space_threshold(profile.tj_offset_threshold);
assert_eq!(config.space_insertion_threshold, profile.tj_offset_threshold);
}
#[test]
fn test_profile_thresholds_in_reasonable_range() {
let profiles = vec![
crate::config::ExtractionProfile::CONSERVATIVE,
crate::config::ExtractionProfile::ACADEMIC,
crate::config::ExtractionProfile::POLICY,
crate::config::ExtractionProfile::FORM,
];
for profile in profiles {
assert!(
profile.tj_offset_threshold < 0.0,
"TJ threshold must be negative ({})",
profile.name
);
assert!(
profile.tj_offset_threshold >= -150.0 && profile.tj_offset_threshold <= -50.0,
"TJ threshold out of range for {} ({})",
profile.name,
profile.tj_offset_threshold
);
assert!(
profile.word_margin_ratio > 0.0 && profile.word_margin_ratio < 1.0,
"Word margin ratio must be between 0 and 1 for {}",
profile.name
);
assert!(
profile.space_threshold_em_ratio > 0.0,
"Space threshold EM ratio must be positive for {}",
profile.name
);
}
}
#[test]
fn test_multiple_profiles_independent() {
let academic = crate::config::ExtractionProfile::for_document_type(crate::config::DocumentType::Academic);
let policy = crate::config::ExtractionProfile::for_document_type(crate::config::DocumentType::Policy);
let academic_config = TextExtractionConfig::with_space_threshold(academic.tj_offset_threshold);
let policy_config = TextExtractionConfig::with_space_threshold(policy.tj_offset_threshold);
assert_ne!(
academic_config.space_insertion_threshold, policy_config.space_insertion_threshold,
"Academic and policy configs should have different thresholds"
);
}
#[test]
fn test_default_config_backward_compatible() {
let default_config = TextExtractionConfig::default();
let conservative_profile = crate::config::ExtractionProfile::CONSERVATIVE;
assert_eq!(
default_config.space_insertion_threshold, conservative_profile.tj_offset_threshold,
"Default config should use conservative threshold for backward compatibility"
);
}