@@ -108,7 +108,7 @@ TYPED_TEST(BruteForceTest, brute_force_vector_update_test) {
108108
109109TYPED_TEST (BruteForceTest, resize_and_align_index) {
110110 size_t dim = 4 ;
111- size_t n = 15 ;
111+ size_t n = 14 ;
112112 size_t blockSize = 10 ;
113113
114114 BFParams params = {
@@ -134,24 +134,26 @@ TYPED_TEST(BruteForceTest, resize_and_align_index) {
134134
135135 // Add another vector, since index size equals to the capacity, this should cause resizing
136136 // (to fit a multiplication of block_size).
137- GenerateAndAddVector<TEST_DATA_T>(index, dim, n + 1 );
137+ GenerateAndAddVector<TEST_DATA_T>(index, dim, n);
138138 ASSERT_EQ (VecSimIndex_IndexSize (index), n + 1 );
139139 // Check new capacity size, should be blockSize * 2.
140140 ASSERT_EQ (bf_index->idToLabelMapping .size (), 2 * blockSize);
141+ ASSERT_EQ (bf_index->idToLabelMapping .capacity (), 2 * blockSize);
141142
142- // Now size = n + 1 = 16 , capacity = 2* bs = 20. Test capacity overflow again
143- // to check that it stays aligned with blocksize .
143+ // Now size = n + 1 (= 15) , capacity = 2 * bs ( = 20) . Test capacity overflow again
144+ // to check that it stays aligned with block size .
144145
145146 size_t add_vectors_count = 8 ;
146147 for (size_t i = 0 ; i < add_vectors_count; i++) {
147148 GenerateAndAddVector<TEST_DATA_T>(index, dim, n + 2 + i, i);
148149 }
149150
150- // Size should be n + 1 + 8 = 24 .
151+ // Size should be n + 1 + 8 (= 25) .
151152 ASSERT_EQ (VecSimIndex_IndexSize (index), n + 1 + add_vectors_count);
152153
153154 // Check new capacity size, should be blockSize * 3.
154155 ASSERT_EQ (bf_index->idToLabelMapping .size (), 3 * blockSize);
156+ ASSERT_EQ (bf_index->idToLabelMapping .capacity (), 3 * blockSize);
155157
156158 VecSimIndex_Free (index);
157159}
@@ -170,7 +172,7 @@ TYPED_TEST(BruteForceTest, resize_and_align_index_largeInitialCapacity) {
170172 BruteForceIndex<TEST_DATA_T, TEST_DIST_T> *bf_index = this ->CastToBF (index);
171173 ASSERT_EQ (VecSimIndex_IndexSize (index), 0 );
172174
173- // add up to blocksize + 1 = 3 + 1 = 4
175+ // Add up to block size + 1 = 3 + 1 = 4
174176 for (size_t i = 0 ; i < bs + 1 ; i++) {
175177 GenerateAndAddVector<TEST_DATA_T>(index, dim, i, i);
176178 }
@@ -190,6 +192,7 @@ TYPED_TEST(BruteForceTest, resize_and_align_index_largeInitialCapacity) {
190192 // 10 - 3 - 10 % 3 (1) = 6
191193 idToLabelMapping_size = bf_index->idToLabelMapping .size ();
192194 ASSERT_EQ (idToLabelMapping_size, n - bs - n % bs);
195+ ASSERT_EQ (idToLabelMapping_size, bf_index->idToLabelMapping .capacity ());
193196
194197 // Delete all the vectors to decrease idToLabelMapping size by another bs.
195198 size_t i = 0 ;
@@ -198,19 +201,24 @@ TYPED_TEST(BruteForceTest, resize_and_align_index_largeInitialCapacity) {
198201 ++i;
199202 }
200203 ASSERT_EQ (bf_index->idToLabelMapping .size (), bs);
204+ ASSERT_EQ (bf_index->idToLabelMapping .capacity (), bs);
205+
201206 // Add and delete a vector to achieve:
202207 // size % block_size == 0 && size + bs <= idToLabelMapping_size(3).
203208 // idToLabelMapping_size should be resized to zero.
204209 GenerateAndAddVector<TEST_DATA_T>(index, dim, 0 );
205210 VecSimIndex_DeleteVector (index, 0 );
206211 ASSERT_EQ (bf_index->idToLabelMapping .size (), 0 );
212+ ASSERT_EQ (bf_index->idToLabelMapping .capacity (), 0 );
207213
208214 // Do it again. This time after adding a vector idToLabelMapping_size is increased by bs.
209215 // Upon deletion it will be resized to zero again.
210216 GenerateAndAddVector<TEST_DATA_T>(index, dim, 0 );
211217 ASSERT_EQ (bf_index->idToLabelMapping .size (), bs);
218+ ASSERT_EQ (bf_index->idToLabelMapping .capacity (), bs);
212219 VecSimIndex_DeleteVector (index, 0 );
213220 ASSERT_EQ (bf_index->idToLabelMapping .size (), 0 );
221+ ASSERT_EQ (bf_index->idToLabelMapping .capacity (), 0 );
214222
215223 VecSimIndex_Free (index);
216224}
0 commit comments