Skip to content

Commit ff65a08

Browse files
committed
added 3 tests, incl. symmetry test. Now 4 in total.
1 parent ece4f28 commit ff65a08

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

src/metrics/distance/jaccard.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ mod tests {
8989
all(target_arch = "wasm32", not(target_os = "wasi")),
9090
wasm_bindgen_test::wasm_bindgen_test
9191
)]
92+
9293
#[test]
9394
fn jaccard_distance() {
9495
let a = vec![1, 0, 1, 1];
@@ -98,4 +99,38 @@ mod tests {
9899

99100
assert!((j - 0.5).abs() < 1e-8);
100101
}
102+
103+
#[test]
104+
fn jaccard_identical_vectors() {
105+
let a = vec![1, 0, 1, 0];
106+
let b = vec![1, 0, 1, 0];
107+
108+
let j: f64 = Jaccard::new().distance(&a, &b);
109+
110+
assert!((j - 0.0).abs() < 1e-8);
111+
}
112+
113+
#[test]
114+
fn jaccard_both_zero_vectors() {
115+
let a = vec![0, 0, 0];
116+
let b = vec![0, 0, 0];
117+
118+
let j: f64 = Jaccard::new().distance(&a, &b);
119+
120+
assert!((j - 0.0).abs() < 1e-8);
121+
}
122+
123+
#[test]
124+
fn jaccard_symmetry() {
125+
let a = vec![1, 0, 1, 1];
126+
let b = vec![0, 1, 1, 0];
127+
128+
let j = Jaccard::new();
129+
130+
let d1 = j.distance(&a, &b);
131+
let d2 = j.distance(&b, &a);
132+
133+
assert!((d1 - d2).abs() < 1e-12);
134+
}
101135
}
136+

0 commit comments

Comments
 (0)