summaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@yahooinc.com>2022-06-01 08:30:44 +0000
committerHåvard Pettersen <havardpe@yahooinc.com>2022-06-07 13:11:26 +0000
commit74a456f904c5eb6d3eca10ac8dad795fd035ccbc (patch)
tree24596df48ee9cc3d25453e408f56611dc92a474c /searchlib/src/tests
parent36663583469ce63be5467907dd8e976d798f8f31 (diff)
fix undefined behavior in unit tests -- WIP
Diffstat (limited to 'searchlib/src/tests')
-rw-r--r--searchlib/src/tests/sortspec/multilevelsort.cpp2
-rw-r--r--searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp4
2 files changed, 4 insertions, 2 deletions
diff --git a/searchlib/src/tests/sortspec/multilevelsort.cpp b/searchlib/src/tests/sortspec/multilevelsort.cpp
index 18c1ef9a615..005fe6bd9d5 100644
--- a/searchlib/src/tests/sortspec/multilevelsort.cpp
+++ b/searchlib/src/tests/sortspec/multilevelsort.cpp
@@ -56,7 +56,7 @@ private:
T getRandomValue() {
T min = std::numeric_limits<T>::min();
T max = std::numeric_limits<T>::max();
- return min + static_cast<T>((max - min) * (((float)rand() / (float)RAND_MAX)));
+ return min + static_cast<T>(double(max - min) * (((float)rand() / (float)RAND_MAX)));
}
template<typename T>
void fill(IntegerAttribute *attr, uint32_t size, uint32_t unique = 0);
diff --git a/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp b/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp
index 6054d473c1f..3d1127e6bc4 100644
--- a/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp
+++ b/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp
@@ -168,7 +168,9 @@ public:
EXPECT_EQ(rv.size(), 3);
EXPECT_LE(rv[0].distance, rv[1].distance);
double thr = (rv[0].distance + rv[1].distance) * 0.5;
- auto got_by_docid = index->find_top_k_with_filter(k, qv, *global_filter, k, thr);
+ auto got_by_docid = (global_filter)
+ ? index->find_top_k_with_filter(k, qv, *global_filter, k, thr)
+ : index->find_top_k(k, qv, k, thr);
EXPECT_EQ(got_by_docid.size(), 1);
EXPECT_EQ(got_by_docid[0].docid, rv[0].docid);
for (const auto & hit : got_by_docid) {