From 2056a882808fdf19c51c4b2de0d0a41e5e14a0ae Mon Sep 17 00:00:00 2001 From: LTLA Date: Thu, 13 Jun 2024 13:33:52 -0700 Subject: [PATCH] Improve re-use of code in the tests. --- tests/src/Hnsw.cpp | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/tests/src/Hnsw.cpp b/tests/src/Hnsw.cpp index d69f8a6..25e4882 100644 --- a/tests/src/Hnsw.cpp +++ b/tests/src/Hnsw.cpp @@ -4,7 +4,7 @@ #include #include -class HnswTest : public ::testing::TestWithParam, int> > { +class TestCore { protected: inline static int nobs, ndim; inline static std::vector data; @@ -57,7 +57,9 @@ class HnswTest : public ::testing::TestWithParam sanity_checks(indices, distances); } +}; +class HnswTest : public TestCore, public ::testing::TestWithParam, int> > { protected: void SetUp() { assemble(std::get<0>(GetParam())); @@ -230,17 +232,14 @@ TEST(Hnsw, Constructor) { EXPECT_EQ(mutant.get_options().num_links, 1000); } -TEST(Hnsw, EuclideanDouble) { - int ndim = 5; - int nobs = 100; - std::vector data(ndim * nobs); - { - std::mt19937_64 rng(1000); - std::normal_distribution dist; - for (auto& d : data) { - d = dist(rng); - } +class HnswMiscTest : public TestCore, public ::testing::Test { +protected: + void SetUp() { + assemble({ 100, 5 }); } +}; + +TEST_F(HnswMiscTest, EuclideanDouble) { knncolle::SimpleMatrix mat(ndim, nobs, data.data()); // using a double as the InternalData_ to check that we dispatch correctly to a SquaredEuclideanDistance. @@ -263,17 +262,7 @@ TEST(Hnsw, EuclideanDouble) { } } -TEST(Hnsw, EuclideanNormalize) { - int ndim = 5; - int nobs = 100; - std::vector data(ndim * nobs); - { - std::mt19937_64 rng(1001); - std::normal_distribution dist; - for (auto& d : data) { - d = dist(rng); - } - } +TEST_F(HnswMiscTest, EuclideanNormalize) { knncolle::SimpleMatrix mat(ndim, nobs, data.data()); // Checking that the normalization option is respected.