mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
vector: indexed-key tests compare keys, not only distances
assert_same accepted a different key at a rank whenever its distance matched, so a lost row replaced by a duplicate passed. It now requires the same keys, and lets two keys trade ranks only when they tie. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK
This commit is contained in:
1 parent
645ea574ad
commit
6265eeaebf
1 file changed
+20
-5
@@ -389,12 +389,27 @@ impl Fixture {
|
||||
|
||||
fn assert_same(got: &[(String, f32)], want: &[(String, f32)], what: &str) {
|
||||
assert_eq!(got.len(), want.len(), "{what}: {got:?} vs {want:?}");
|
||||
// Ties may come back in either order: the same keys, and the same
|
||||
// distance at each rank.
|
||||
fn keys(hits: &[(String, f32)]) -> Vec<&str> {
|
||||
let mut keys: Vec<&str> = hits.iter().map(|(k, _)| k.as_str()).collect();
|
||||
keys.sort();
|
||||
keys
|
||||
}
|
||||
assert_eq!(keys(got), keys(want), "{what}: {got:?} vs {want:?}");
|
||||
for (g, w) in got.iter().zip(want) {
|
||||
let same = g.0 == w.0 || (g.1 - w.1).abs() < 1e-4;
|
||||
assert!(
|
||||
same && ((g.1 - w.1).abs() < 1e-4 || (g.1.is_infinite() && w.1.is_infinite())),
|
||||
"{what}: {got:?} vs {want:?}"
|
||||
);
|
||||
let same = (g.1 - w.1).abs() < 1e-4 || (g.1.is_infinite() && w.1.is_infinite());
|
||||
assert!(same, "{what}: {got:?} vs {want:?}");
|
||||
if g.0 != w.0 {
|
||||
let tie = want
|
||||
.iter()
|
||||
.any(|(k, d)| k == &g.0 && (d - w.1).abs() < 1e-4);
|
||||
assert!(
|
||||
tie,
|
||||
"{what}: {} at {} is no tie: {got:?} vs {want:?}",
|
||||
g.0, g.1
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user