@@ -800,10 +800,10 @@ TYPED_TEST_P(SmallTableResizeTest, InsertIntoSmallTable) {
800800}
801801
802802TYPED_TEST_P (SmallTableResizeTest, ResizeGrowSmallTables) {
803- TypeParam t;
804803 for (size_t source_size = 0 ; source_size < 32 ; ++source_size) {
805804 for (size_t target_size = source_size; target_size < 32 ; ++target_size) {
806805 for (bool rehash : {false , true }) {
806+ TypeParam t;
807807 for (size_t i = 0 ; i < source_size; ++i) {
808808 t.insert (static_cast <int >(i));
809809 }
@@ -822,9 +822,10 @@ TYPED_TEST_P(SmallTableResizeTest, ResizeGrowSmallTables) {
822822}
823823
824824TYPED_TEST_P (SmallTableResizeTest, ResizeReduceSmallTables) {
825- TypeParam t;
826825 for (size_t source_size = 0 ; source_size < 32 ; ++source_size) {
827826 for (size_t target_size = 0 ; target_size <= source_size; ++target_size) {
827+ TypeParam t;
828+ t.reserve (source_size);
828829 size_t inserted_count = std::min<size_t >(source_size, 5 );
829830 for (size_t i = 0 ; i < inserted_count; ++i) {
830831 t.insert (static_cast <int >(i));
@@ -2282,20 +2283,34 @@ TEST(Table, IterationOrderChangesByInstance) {
22822283}
22832284
22842285TEST (Table, IterationOrderChangesOnRehash) {
2285- std::vector<IntTable> garbage;
2286- for (int i = 0 ; i < 5000 ; ++i) {
2287- auto t = MakeSimpleTable (20 );
2288- const auto reference = OrderOfIteration (t);
2289- // Force rehash to the same size.
2290- t.rehash (0 );
2291- auto trial = OrderOfIteration (t);
2292- if (trial != reference) {
2293- // We are done.
2294- return ;
2286+ // We test different sizes with many small numbers, because small table
2287+ // resize has a different codepath.
2288+ // Note: iteration order for size() <= 1 is always the same.
2289+ for (size_t size : std::vector<size_t >{2 , 3 , 6 , 7 , 12 , 15 , 20 , 50 }) {
2290+ for (size_t rehash_size : {
2291+ size_t {0 }, // Force rehash is guaranteed.
2292+ size * 10 // Rehash to the larger capacity is guaranteed.
2293+ }) {
2294+ std::vector<IntTable> garbage;
2295+ bool ok = false ;
2296+ for (int i = 0 ; i < 5000 ; ++i) {
2297+ auto t = MakeSimpleTable (size);
2298+ const auto reference = OrderOfIteration (t);
2299+ // Force rehash.
2300+ t.rehash (rehash_size);
2301+ auto trial = OrderOfIteration (t);
2302+ if (trial != reference) {
2303+ // We are done.
2304+ ok = true ;
2305+ break ;
2306+ }
2307+ garbage.push_back (std::move (t));
2308+ }
2309+ EXPECT_TRUE (ok)
2310+ << " Iteration order remained the same across many attempts " << size
2311+ << " ->" << rehash_size << " ." ;
22952312 }
2296- garbage.push_back (std::move (t));
22972313 }
2298- FAIL () << " Iteration order remained the same across many attempts." ;
22992314}
23002315
23012316// Verify that pointers are invalidated as soon as a second element is inserted.
0 commit comments