Skip to content

Commit 2583dae

Browse files
committed
Added more tests for search
1 parent 4f9ddbe commit 2583dae

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

test/index_binary_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ def test_remove_ids
5656
assert_equal [1, 0, -1], ids[0, true].to_a
5757
end
5858

59+
def test_search
60+
objects = [
61+
[1, 1, 2, 1],
62+
[5, 4, 6, 5],
63+
[1, 2, 1, 2]
64+
]
65+
index = Faiss::IndexBinaryFlat.new(32)
66+
index.add(objects)
67+
68+
distances, ids = index.search([[1, 1, 2, 1]], 5)
69+
assert_equal [0, 1, 2, -1, -1], ids[0, true].to_a
70+
assert_equal [0, 5, 6, 2147483647, 2147483647], distances[0, true].to_a
71+
end
72+
5973
def test_search_zero_k
6074
objects = [
6175
[1, 1, 2, 1],

test/index_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,20 @@ def test_remove_ids_empty
336336
assert_equal 0, index.remove_ids([])
337337
end
338338

339+
def test_search
340+
objects = [
341+
[1, 1, 2, 1],
342+
[5, 4, 6, 5],
343+
[1, 2, 1, 2]
344+
]
345+
index = Faiss::IndexFlatL2.new(4)
346+
index.add(objects)
347+
348+
distances, ids = index.search([[1, 1, 2, 1]], 5)
349+
assert_equal [0, 2, 1, -1, -1], ids[0, true].to_a
350+
assert_equal [0, 3, 57, 3.4028234663852886e+38, 3.4028234663852886e+38], distances[0, true].to_a
351+
end
352+
339353
def test_search_zero_k
340354
objects = [
341355
[1, 1, 2, 1],

0 commit comments

Comments
 (0)