Added test for levenshtein distance
This commit is contained in:
parent
656a75b224
commit
aa79b75b59
28
src/io.rs
28
src/io.rs
|
|
@ -211,7 +211,8 @@ fn find_role_from_string(group: Option<String>, roles: Vec<String>) -> Option<St
|
|||
}
|
||||
|
||||
let group = group.unwrap();
|
||||
let mut lowest: (Option<String>, usize) = (None, group.len() + 5);
|
||||
// We are hard-coding the maximum value above which we prefer returning None rather than a guess
|
||||
let mut lowest: (Option<String>, usize) = (None, 5);
|
||||
for role in roles {
|
||||
let d = levenshtein(&role, &group);
|
||||
if d < lowest.1 {
|
||||
|
|
@ -371,5 +372,28 @@ pub async fn discord_main_loop() {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
// use super::*;
|
||||
use super::*;
|
||||
#[test]
|
||||
fn test_levenshtein() {
|
||||
let arguments: Vec<String> = vec![
|
||||
"hunters",
|
||||
"ffxiv_idle",
|
||||
"ffxiv_progfish",
|
||||
"ffxiv_minilvl",
|
||||
"dbd",
|
||||
"dnd",
|
||||
"r6",
|
||||
"apex",
|
||||
"boardgames",
|
||||
]
|
||||
.iter()
|
||||
.map(|v| v.to_string())
|
||||
.collect();
|
||||
println!("{:?}", arguments);
|
||||
println!(
|
||||
"{:?}",
|
||||
find_role_from_string(Some("bodyoncetoldme".to_string()), arguments.clone())
|
||||
);
|
||||
assert!(find_role_from_string(Some("bodyoncetoldme".to_string()), arguments).is_none())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue