Skip to content

Commit 7cf79eb

Browse files
jbrummackJulius Brummack
and
Julius Brummack
authored
Improve: Test wrong number of dimensions in Rust (#413)
Closes #412 --------- Co-authored-by: Julius Brummack <juliusbrummack@icloud.com>
1 parent da7a86c commit 7cf79eb

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

rust/lib.rs

+25
Original file line numberDiff line numberDiff line change
@@ -1373,8 +1373,12 @@ mod tests {
13731373

13741374
let first: [f32; 5] = [0.2, 0.1, 0.2, 0.1, 0.3];
13751375
let second: [f32; 5] = [0.3, 0.2, 0.4, 0.0, 0.1];
1376+
let too_long: [f32; 6] = [0.3, 0.2, 0.4, 0.0, 0.1, 0.1];
1377+
let too_short: [f32; 4] = [0.3, 0.2, 0.4, 0.0];
13761378
assert!(index.add(1, &first).is_ok());
13771379
assert!(index.add(2, &second).is_ok());
1380+
assert!(index.add(3, &too_long).is_err());
1381+
assert!(index.add(4, &too_short).is_err());
13781382
assert_eq!(index.size(), 2);
13791383

13801384
// Test using Vec<T>
@@ -1393,6 +1397,27 @@ mod tests {
13931397
let result = index.get(1, &mut found);
13941398
assert!(result.is_err());
13951399
}
1400+
#[test]
1401+
fn test_search_vector() {
1402+
let mut options = IndexOptions::default();
1403+
options.dimensions = 5;
1404+
options.quantization = ScalarKind::F32;
1405+
let index = Index::new(&options).unwrap();
1406+
assert!(index.reserve(10).is_ok());
1407+
1408+
let first: [f32; 5] = [0.2, 0.1, 0.2, 0.1, 0.3];
1409+
let second: [f32; 5] = [0.3, 0.2, 0.4, 0.0, 0.1];
1410+
let too_long: [f32; 6] = [0.3, 0.2, 0.4, 0.0, 0.1, 0.1];
1411+
let too_short: [f32; 4] = [0.3, 0.2, 0.4, 0.0];
1412+
assert!(index.add(1, &first).is_ok());
1413+
assert!(index.add(2, &second).is_ok());
1414+
assert_eq!(index.size(), 2);
1415+
//assert!(index.add(3, &too_long).is_err());
1416+
//assert!(index.add(4, &too_short).is_err());
1417+
1418+
assert!(index.search(&too_long, 1).is_err());
1419+
assert!(index.search(&too_short, 1).is_err());
1420+
}
13961421

13971422
#[test]
13981423
fn test_add_remove_vector() {

0 commit comments

Comments
 (0)