1919
2020#include " iceberg/update/update_statistics.h"
2121
22+ #include < algorithm>
2223#include < memory>
2324
2425#include < gmock/gmock.h>
@@ -54,6 +55,16 @@ class UpdateStatisticsTest : public UpdateTestBase {
5455
5556 return stats_file;
5657 }
58+
59+ // Helper to find statistics file by snapshot_id in the result vector
60+ std::shared_ptr<StatisticsFile> FindStatistics (
61+ const std::vector<std::pair<int64_t , std::shared_ptr<StatisticsFile>>>& to_set,
62+ int64_t snapshot_id) {
63+ auto it = std::find_if (to_set.begin (), to_set.end (), [snapshot_id](const auto & p) {
64+ return p.first == snapshot_id;
65+ });
66+ return it != to_set.end () ? it->second : nullptr ;
67+ }
5768};
5869
5970TEST_F (UpdateStatisticsTest, EmptyUpdate) {
@@ -72,7 +83,7 @@ TEST_F(UpdateStatisticsTest, SetStatistics) {
7283 ICEBERG_UNWRAP_OR_FAIL (auto result, update->Apply ());
7384 EXPECT_EQ (result.to_set .size (), 1 );
7485 EXPECT_TRUE (result.to_remove .empty ());
75- EXPECT_EQ (result.to_set . at ( 1 ), stats_file);
86+ EXPECT_EQ (FindStatistics ( result.to_set , 1 ), stats_file);
7687}
7788
7889TEST_F (UpdateStatisticsTest, SetMultipleStatistics) {
@@ -87,8 +98,8 @@ TEST_F(UpdateStatisticsTest, SetMultipleStatistics) {
8798 ICEBERG_UNWRAP_OR_FAIL (auto result, update->Apply ());
8899 EXPECT_EQ (result.to_set .size (), 2 );
89100 EXPECT_TRUE (result.to_remove .empty ());
90- EXPECT_EQ (result.to_set . at ( 1 ), stats_file_1);
91- EXPECT_EQ (result.to_set . at ( 2 ), stats_file_2);
101+ EXPECT_EQ (FindStatistics ( result.to_set , 1 ), stats_file_1);
102+ EXPECT_EQ (FindStatistics ( result.to_set , 2 ), stats_file_2);
92103}
93104
94105TEST_F (UpdateStatisticsTest, RemoveStatistics) {
@@ -120,7 +131,7 @@ TEST_F(UpdateStatisticsTest, SetAndRemoveDifferentSnapshots) {
120131
121132 ICEBERG_UNWRAP_OR_FAIL (auto result, update->Apply ());
122133 EXPECT_EQ (result.to_set .size (), 1 );
123- EXPECT_EQ (result.to_set . at ( 1 ), stats_file);
134+ EXPECT_EQ (FindStatistics ( result.to_set , 1 ), stats_file);
124135 EXPECT_EQ (result.to_remove .size (), 1 );
125136 EXPECT_THAT (result.to_remove , ::testing::Contains (2 ));
126137}
@@ -139,8 +150,8 @@ TEST_F(UpdateStatisticsTest, ReplaceStatistics) {
139150 EXPECT_EQ (result.to_set .size (), 1 );
140151 EXPECT_TRUE (result.to_remove .empty ());
141152 // Should have the second one (replacement)
142- EXPECT_EQ (result.to_set . at ( 1 ), stats_file_2);
143- EXPECT_NE (result.to_set . at ( 1 ), stats_file_1);
153+ EXPECT_EQ (FindStatistics ( result.to_set , 1 ), stats_file_2);
154+ EXPECT_NE (FindStatistics ( result.to_set , 1 ), stats_file_1);
144155}
145156
146157TEST_F (UpdateStatisticsTest, SetThenRemoveSameSnapshot) {
@@ -168,7 +179,7 @@ TEST_F(UpdateStatisticsTest, RemoveThenSetSameSnapshot) {
168179 ICEBERG_UNWRAP_OR_FAIL (auto result, update->Apply ());
169180 EXPECT_EQ (result.to_set .size (), 1 );
170181 EXPECT_TRUE (result.to_remove .empty ());
171- EXPECT_EQ (result.to_set . at ( 1 ), stats_file);
182+ EXPECT_EQ (FindStatistics ( result.to_set , 1 ), stats_file);
172183}
173184
174185TEST_F (UpdateStatisticsTest, SetNullStatistics) {
0 commit comments