Skip to content

Commit

Permalink
lua: add test of range errors
Browse files Browse the repository at this point in the history
The test is similar to spotify#154
  • Loading branch information
starius committed May 1, 2016
1 parent 8274086 commit a6f229a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/annoy_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ end)

describe("types test", function()

local n_points = 1000
local n_trees = 10

-- tests "numpy" and "tuple" are not applicable to Lua
Expand All @@ -515,6 +516,29 @@ describe("types test", function()
i:build(n_trees)
end)

it("range_errors", function()
local f = 10
local i = AnnoyIndex(f, 'euclidean')
for j = 0, n_points - 1 do
i:add_item(j, randomVector(f, 0, 1))
end
assert.has_error(function()
i:add_item(-1, randomVector(f))
end)
i:build(n_trees)
for _, bad_index in ipairs({-1000, -1, n_points, n_points + 1000}) do
assert.has_error(function()
i:get_distance(0, bad_index)
end)
assert.has_error(function()
i:get_nns_by_item(bad_index, 1)
end)
assert.has_error(function()
i:get_item_vector(bad_index)
end)
end
end)

end)

describe("memory leaks", function()
Expand Down

0 comments on commit a6f229a

Please sign in to comment.