mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 23:04:26 +01:00
add word derivations tests
This commit is contained in:
parent
d5ddc6b080
commit
9fe40df960
@ -398,4 +398,67 @@ mod test {
|
||||
search.authorize_typos(true);
|
||||
assert!(!search.is_typo_authorized().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_one_typos_tolerance() {
|
||||
let fst = fst::Set::from_iter(["zealand"].iter()).unwrap().map_data(Cow::Owned).unwrap();
|
||||
let mut cache = HashMap::new();
|
||||
let found = word_derivations("zealend", false, 1, &fst, &mut cache).unwrap();
|
||||
|
||||
assert_eq!(found, &[("zealand".to_string(), 1)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_one_typos_first_letter() {
|
||||
let fst = fst::Set::from_iter(["zealand"].iter()).unwrap().map_data(Cow::Owned).unwrap();
|
||||
let mut cache = HashMap::new();
|
||||
let found = word_derivations("sealand", false, 1, &fst, &mut cache).unwrap();
|
||||
|
||||
assert_eq!(found, &[]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_two_typos_tolerance() {
|
||||
let fst = fst::Set::from_iter(["zealand"].iter()).unwrap().map_data(Cow::Owned).unwrap();
|
||||
let mut cache = HashMap::new();
|
||||
let found = word_derivations("zealemd", false, 2, &fst, &mut cache).unwrap();
|
||||
|
||||
assert_eq!(found, &[("zealand".to_string(), 2)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_two_typos_first_letter() {
|
||||
let fst = fst::Set::from_iter(["zealand"].iter()).unwrap().map_data(Cow::Owned).unwrap();
|
||||
let mut cache = HashMap::new();
|
||||
let found = word_derivations("sealand", false, 2, &fst, &mut cache).unwrap();
|
||||
|
||||
assert_eq!(found, &[("zealand".to_string(), 2)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_prefix() {
|
||||
let fst = fst::Set::from_iter(["zealand"].iter()).unwrap().map_data(Cow::Owned).unwrap();
|
||||
let mut cache = HashMap::new();
|
||||
let found = word_derivations("ze", true, 0, &fst, &mut cache).unwrap();
|
||||
|
||||
assert_eq!(found, &[("zealand".to_string(), 0)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bad_prefix() {
|
||||
let fst = fst::Set::from_iter(["zealand"].iter()).unwrap().map_data(Cow::Owned).unwrap();
|
||||
let mut cache = HashMap::new();
|
||||
let found = word_derivations("se", true, 0, &fst, &mut cache).unwrap();
|
||||
|
||||
assert_eq!(found, &[]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_prefix_with_typo() {
|
||||
let fst = fst::Set::from_iter(["zealand"].iter()).unwrap().map_data(Cow::Owned).unwrap();
|
||||
let mut cache = HashMap::new();
|
||||
let found = word_derivations("zae", true, 1, &fst, &mut cache).unwrap();
|
||||
|
||||
assert_eq!(found, &[("zealand".to_string(), 1)]);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user