diff --git a/tests/test_hnsw.cpp b/tests/test_hnsw.cpp index 29e196cb2dde8465f988ffc3afa99f335df60a11..914fb5262e4c8e28606f404b5c28989cb21ad665 100644 --- a/tests/test_hnsw.cpp +++ b/tests/test_hnsw.cpp @@ -43,6 +43,35 @@ int test_insert() { return 1; } +int test_search() { + // Set dimensions holders and get the data. + size_t d, n; + float *xd = fvecs_read("sift_query.fvecs", &d, &n); + + // Conversion. + int *data = float_to_int(xd, d * n); + + // Cast d to integer. + int d_int = static_cast<int>(d); + + // Encrypt the first three vectors. + Key key = setup(d_int); + Item *encrypted_data = encrypt_data(data, key, d, 6); + + // Get the HNSW object. + HNSWGraph index(10, 30, 10, 40, 4, key, 10, 100); + + // Do the insert. + for (int i = 0; i < 5; i++) index.insert(encrypted_data[i]); + + // Check for whether the data is correct. + vector<int> result = index.search(encrypted_data[5], 3); + + if (result.size() != 3) return 0; + + return 1; +} + int main() { // Init core and setup. @@ -52,6 +81,7 @@ int main() { // Perform tests. if (test_constructor() != 1) return 1; if (test_insert() != 1) return 1; + if (test_search() != 1) return 1; return 0; } \ No newline at end of file