forked from lexi-sh/rs-natural
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistance_tests.rs
31 lines (26 loc) · 978 Bytes
/
distance_tests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
extern crate natural;
use natural::distance::jaro_winkler_distance;
use natural::distance::levenshtein_distance;
#[test]
fn test_jaro_winkler() {
f64_eq(jaro_winkler_distance("one", "one"), 1f32);
f64_eq(jaro_winkler_distance("one", ""), 0f32);
f64_eq(jaro_winkler_distance("", ""), 0f32);
f64_eq(jaro_winkler_distance("", "one"), 0f32);
f64_eq(jaro_winkler_distance("DWAYNE", "DUANE"), 0.822);
f64_eq(jaro_winkler_distance("Martha", "Marhta"), 0.944);
f64_eq(jaro_winkler_distance("dicksonx", "dixon"), 0.767);
}
fn f64_eq(a: f32, b: f32) {
assert!((a - b).abs() < 0.01);
}
// TODO: test lev distance
#[test]
fn test_lev_distance() {
assert_eq!(levenshtein_distance("", ""), 0);
assert_eq!(levenshtein_distance("one", "one"), 0);
assert_eq!(levenshtein_distance("one", ""), 3);
assert_eq!(levenshtein_distance("", "one"), 3);
assert_eq!(levenshtein_distance("kitten", "sitting"), 3);
assert_eq!(levenshtein_distance("sitting", "kitten"), 3);
}