summaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2020-06-12 07:36:20 +0000
committerArne Juul <arnej@verizonmedia.com>2020-06-12 07:36:20 +0000
commit4faeb6fb379e812ff639ec13aaeb217e77578621 (patch)
treeca14ceb5e1d3ac8487f62ce377a61a242e2a1092 /searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp
parent73edac0b7a44a0c3881ca34eea5e525a0a253097 (diff)
revert back to getting random number in the [0,1) range
* for whatever reason, std::uniform_real_distribution doesn't allow a>b when specifying the [a,b) half-open range. So we need to get a number from [0,1) and then do (1.0-unif) to convert to the (0,1] range that we want. * extend the unit test with more initial numbers, and write it in a more compact way.
Diffstat (limited to 'searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp')
-rw-r--r--searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp34
1 files changed, 25 insertions, 9 deletions
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 04f2076121f..b49292463bd 100644
--- a/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp
+++ b/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp
@@ -521,15 +521,31 @@ TEST_F(HnswIndexTest, shrink_called_heuristic)
TEST(LevelGeneratorTest, gives_various_levels)
{
InvLogLevelGenerator generator(4);
- EXPECT_EQ(2u, generator.max_level());
- EXPECT_EQ(1u, generator.max_level());
- EXPECT_EQ(0u, generator.max_level());
- EXPECT_EQ(1u, generator.max_level());
- EXPECT_EQ(0u, generator.max_level());
- EXPECT_EQ(1u, generator.max_level());
- EXPECT_EQ(0u, generator.max_level());
- EXPECT_EQ(0u, generator.max_level());
- EXPECT_EQ(0u, generator.max_level());
+ std::vector<uint32_t> got_levels(16);
+ for (auto & v : got_levels) { v = generator.max_level(); }
+ EXPECT_EQ(got_levels, std::vector<uint32_t>({
+ 2, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0
+ }));
+ for (auto & v : got_levels) { v = generator.max_level(); }
+ EXPECT_EQ(got_levels, std::vector<uint32_t>({
+ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ }));
+ for (auto & v : got_levels) { v = generator.max_level(); }
+ EXPECT_EQ(got_levels, std::vector<uint32_t>({
+ 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0
+ }));
+ for (auto & v : got_levels) { v = generator.max_level(); }
+ EXPECT_EQ(got_levels, std::vector<uint32_t>({
+ 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1
+ }));
+ for (auto & v : got_levels) { v = generator.max_level(); }
+ EXPECT_EQ(got_levels, std::vector<uint32_t>({
+ 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 2
+ }));
+ for (auto & v : got_levels) { v = generator.max_level(); }
+ EXPECT_EQ(got_levels, std::vector<uint32_t>({
+ 0, 1, 1, 0, 3, 1, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0
+ }));
uint32_t left = 1000000;
std::vector<uint32_t> hist;