use crate::types::IntendedUse;
pub(crate) const CHAPTER38_CATCH_ALL_CODE: &str = "382499";
pub(crate) const CHAPTER38_CATCH_ALL_DESC: &str =
"Chemical preparations, not elsewhere specified or included (Ch. 38 NEC)";
pub(crate) fn classify_by_intended_use(
intended_use: &IntendedUse,
) -> Option<(&'static str, &'static str, f32)> {
match intended_use {
IntendedUse::Agricultural => Some((
"380800",
"Insecticides, rodenticides, fungicides, herbicides, \
anti-sprouting products and plant-growth regulators, \
disinfectants and similar products (Ch. 38.08)",
0.75,
)),
IntendedUse::Pharmaceutical => None,
IntendedUse::Cosmetic => None,
IntendedUse::Food => None,
IntendedUse::Industrial | IntendedUse::Other(_) => None,
}
}
pub(crate) fn special_chapter_by_use(
intended_use: &IntendedUse,
) -> Option<(&'static str, &'static str, f32)> {
match intended_use {
IntendedUse::Pharmaceutical => Some((
"300490",
"Medicaments — other mixtures/preparations for therapeutic use (Ch. 30)",
0.70,
)),
IntendedUse::Cosmetic => Some((
"330499",
"Beauty/cosmetic preparations — other (Ch. 33)",
0.65,
)),
IntendedUse::Food => Some((
"210690",
"Food preparations, not elsewhere specified (Ch. 21)",
0.65,
)),
_ => None,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn agricultural_gives_3808() {
let (code, _, confidence) =
classify_by_intended_use(&IntendedUse::Agricultural).unwrap();
assert_eq!(&code[..2], "38");
assert!(confidence > 0.5);
}
#[test]
fn pharmaceutical_returns_none_from_ch38_function() {
assert!(classify_by_intended_use(&IntendedUse::Pharmaceutical).is_none());
}
#[test]
fn pharmaceutical_gives_ch30_via_special() {
let (code, _, _) = special_chapter_by_use(&IntendedUse::Pharmaceutical).unwrap();
assert_eq!(&code[..2], "30");
}
#[test]
fn cosmetic_gives_ch33_via_special() {
let (code, _, _) = special_chapter_by_use(&IntendedUse::Cosmetic).unwrap();
assert_eq!(&code[..2], "33");
}
#[test]
fn food_gives_ch21_via_special() {
let (code, _, _) = special_chapter_by_use(&IntendedUse::Food).unwrap();
assert_eq!(&code[..2], "21");
}
#[test]
fn industrial_returns_none() {
assert!(classify_by_intended_use(&IntendedUse::Industrial).is_none());
}
#[test]
fn catch_all_is_6_digits() {
assert_eq!(CHAPTER38_CATCH_ALL_CODE.len(), 6);
assert!(CHAPTER38_CATCH_ALL_CODE.chars().all(|c| c.is_ascii_digit()));
}
}