From 5b2e85bb565ba338a092d52dc98a2394dfa95ca3 Mon Sep 17 00:00:00 2001
From: Weiqi <weltch1997@gmail.com>
Date: Thu, 27 Apr 2023 05:51:26 -0400
Subject: [PATCH] Done with the hnsw

---
 tests/test_hnsw.cpp | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tests/test_hnsw.cpp b/tests/test_hnsw.cpp
index 29e196c..914fb52 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
-- 
GitLab