MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / assert_rejects_mismatch

Function assert_rejects_mismatch

nodedb-vector/tests/simd_length_safety.rs:16–31  ·  view source on GitHub ↗
(metric: DistanceMetric)

Source from the content-addressed store, hash-verified

14use nodedb_vector::distance::distance;
15
16fn assert_rejects_mismatch(metric: DistanceMetric) {
17 // a.len() = 9 forces one 8-wide SIMD chunk + remainder. b.len() = 1
18 // means any unchecked 256-bit load from b is a buffer overrun. A correct
19 // dispatcher either rejects the call (panic) or bounds iteration by
20 // `min(a.len(), b.len())`; both surface as a deterministic panic today
21 // because the scalar remainder loop indexes `b[i]` out of bounds.
22 let a = vec![1.0f32; 9];
23 let b = vec![1.0f32; 1];
24
25 let result = std::panic::catch_unwind(|| distance(&a, &b, metric));
26 assert!(
27 result.is_err(),
28 "distance({metric:?}) must reject length mismatch (a.len()=9, b.len()=1) \
29 instead of reading past the shorter buffer"
30 );
31}
32
33#[test]
34fn l2_rejects_length_mismatch() {

Calls 1

distanceFunction · 0.50

Tested by

no test coverage detected