@@ -71,12 +71,15 @@ void test_generate_table_data_with_default_timestamp() {
7171 auto table_data = columns_csv.generate ();
7272
7373 assert (table_data.size () == 1 && " Expected 1 table" );
74- assert (table_data[0 ].timestamps .size () == 2 && " Expected 2 timestamps" );
75- assert (table_data[0 ].timestamps [0 ] == 1622505600000 && " Expected first timestamp to match" );
76- assert (table_data[0 ].timestamps [1 ] == 1622592000000 && " Expected second timestamp to match" );
77- assert (table_data[0 ].rows .size () == 2 && " Expected 2 rows of data" );
78- assert (std::get<std::string>(table_data[0 ].rows [0 ][0 ]) == " Alice" && " Expected first column to be 'Alice'" );
79- assert (std::get<std::string>(table_data[0 ].rows [0 ][1 ]) == " New York" && " Expected second column to be 'New York'" );
74+ const auto & table_pair = *table_data.begin ();
75+ const auto & table = table_pair.second ;
76+
77+ assert (table.timestamps .size () == 2 && " Expected 2 timestamps" );
78+ assert (table.timestamps [0 ] == 1622505600000 && " Expected first timestamp to match" );
79+ assert (table.timestamps [1 ] == 1622592000000 && " Expected second timestamp to match" );
80+ assert (table.rows .size () == 2 && " Expected 2 rows of data" );
81+ assert (std::get<std::string>(table.rows [0 ][0 ]) == " Alice" && " Expected first column to be 'Alice'" );
82+ assert (std::get<std::string>(table.rows [0 ][1 ]) == " New York" && " Expected second column to be 'New York'" );
8083 std::cout << " test_generate_table_data_with_default_timestamp passed\n " ;
8184}
8285
@@ -106,12 +109,15 @@ void test_generate_table_data_with_timestamp() {
106109 auto table_data = columns_csv.generate ();
107110
108111 assert (table_data.size () == 1 && " Expected 1 table" );
109- assert (table_data[0 ].timestamps .size () == 2 && " Expected 2 timestamps" );
110- assert (table_data[0 ].timestamps [0 ] == 1622505600000 && " Expected first timestamp to match" );
111- assert (table_data[0 ].timestamps [1 ] == 1622592000000 && " Expected second timestamp to match" );
112- assert (table_data[0 ].rows .size () == 2 && " Expected 2 rows of data" );
113- assert (std::get<std::string>(table_data[0 ].rows [0 ][0 ]) == " Alice" && " Expected first column to be 'Alice'" );
114- assert (std::get<std::string>(table_data[0 ].rows [0 ][1 ]) == " New York" && " Expected second column to be 'New York'" );
112+ const auto & table_pair = *table_data.begin ();
113+ const auto & table = table_pair.second ;
114+
115+ assert (table.timestamps .size () == 2 && " Expected 2 timestamps" );
116+ assert (table.timestamps [0 ] == 1622505600000 && " Expected first timestamp to match" );
117+ assert (table.timestamps [1 ] == 1622592000000 && " Expected second timestamp to match" );
118+ assert (table.rows .size () == 2 && " Expected 2 rows of data" );
119+ assert (std::get<std::string>(table.rows [0 ][0 ]) == " Alice" && " Expected first column to be 'Alice'" );
120+ assert (std::get<std::string>(table.rows [0 ][1 ]) == " New York" && " Expected second column to be 'New York'" );
115121 std::cout << " test_generate_table_data_with_timestamp passed\n " ;
116122}
117123
@@ -140,15 +146,17 @@ void test_generate_table_data_with_generated_timestamp() {
140146 auto table_data = columns_csv.generate ();
141147
142148 assert (table_data.size () == 1 && " Expected 1 table" );
143- assert (table_data[0 ].timestamps .size () == 2 && " Expected 2 timestamps" );
144- assert (table_data[0 ].rows .size () == 2 && " Expected 2 rows of data" );
145- assert (std::get<std::string>(table_data[0 ].rows [0 ][0 ]) == " Alice" && " Expected first column to be 'Alice'" );
146- assert (std::get<int32_t >(table_data[0 ].rows [0 ][1 ]) == 30 && " Expected second column to be 30" );
147- assert (std::get<std::string>(table_data[0 ].rows [0 ][2 ]) == " New York" && " Expected third column to be 'New York'" );
149+ const auto & table_pair = *table_data.begin ();
150+ const auto & table = table_pair.second ;
151+
152+ assert (table.timestamps .size () == 2 && " Expected 2 timestamps" );
153+ assert (table.rows .size () == 2 && " Expected 2 rows of data" );
154+ assert (std::get<std::string>(table.rows [0 ][0 ]) == " Alice" && " Expected first column to be 'Alice'" );
155+ assert (std::get<int32_t >(table.rows [0 ][1 ]) == 30 && " Expected second column to be 30" );
156+ assert (std::get<std::string>(table.rows [0 ][2 ]) == " New York" && " Expected third column to be 'New York'" );
148157 std::cout << " test_generate_table_data_with_generated_timestamp passed\n " ;
149158}
150159
151-
152160void test_generate_table_data_include_tbname () {
153161 ColumnsCSV config;
154162 config.file_path = " include_tbname.csv" ;
@@ -175,30 +183,20 @@ void test_generate_table_data_include_tbname() {
175183 assert (table_data.size () == 2 && " Expected 2 tables" );
176184
177185 // Check table names and data
178- bool table1_found = false ;
179- bool table2_found = false ;
180-
181- for (const auto & table : table_data) {
182- if (table.table_name == " table1" ) {
183- table1_found = true ;
184- assert (table.timestamps .size () == 1 && " Expected 1 timestamp for table1" );
185- assert (table.rows .size () == 1 && " Expected 1 row of data for table1" );
186- assert (std::get<int32_t >(table.rows [0 ][0 ]) == 30 && " Expected first column to be 30 for table1" );
187- assert (std::get<std::string>(table.rows [0 ][1 ]) == " New York" && " Expected second column to be 'New York' for table1" );
188- } else if (table.table_name == " table2" ) {
189- table2_found = true ;
190- assert (table.timestamps .size () == 1 && " Expected 1 timestamp for table2" );
191- assert (table.rows .size () == 1 && " Expected 1 row of data for table2" );
192- assert (std::get<int32_t >(table.rows [0 ][0 ]) == 25 && " Expected first column to be 25 for table2" );
193- assert (std::get<std::string>(table.rows [0 ][1 ]) == " Los Angeles" && " Expected second column to be 'Los Angeles' for table2" );
194- }
195- }
186+ assert (table_data.find (" table1" ) != table_data.end () && " Expected table1 to be found" );
187+ assert (table_data.find (" table2" ) != table_data.end () && " Expected table2 to be found" );
188+
189+ const auto & table1 = table_data.at (" table1" );
190+ assert (table1.timestamps .size () == 1 && " Expected 1 timestamp for table1" );
191+ assert (table1.rows .size () == 1 && " Expected 1 row of data for table1" );
192+ assert (std::get<int32_t >(table1.rows [0 ][0 ]) == 30 && " Expected first column to be 30 for table1" );
193+ assert (std::get<std::string>(table1.rows [0 ][1 ]) == " New York" && " Expected second column to be 'New York' for table1" );
196194
197- // Verify both tables are found
198- ( void )table1_found ;
199- ( void )table2_found ;
200- assert (table1_found && " Expected table1 to be found " );
201- assert (table2_found && " Expected table2 to be found " );
195+ const auto & table2 = table_data. at ( " table2 " );
196+ assert (table2. timestamps . size () == 1 && " Expected 1 timestamp for table2 " ) ;
197+ assert (table2. rows . size () == 1 && " Expected 1 row of data for table2 " ) ;
198+ assert (std::get< int32_t >(table2. rows [ 0 ][ 0 ]) == 25 && " Expected first column to be 25 for table2 " );
199+ assert (std::get<std::string>(table2. rows [ 0 ][ 1 ]) == " Los Angeles " && " Expected second column to be 'Los Angeles' for table2 " );
202200
203201 std::cout << " test_generate_table_data_include_tbname passed\n " ;
204202}
@@ -223,11 +221,15 @@ void test_generate_table_data_default_column_types() {
223221 auto table_data = columns_csv.generate ();
224222
225223 assert (table_data.size () == 1 && " Expected 1 table" );
226- assert (table_data[0 ].rows .size () == 2 && " Expected 2 rows of data" );
227- assert (std::get<std::string>(table_data[0 ].rows [0 ][0 ]) == " Alice" && " Expected first column to be 'Alice'" );
228- assert (std::get<std::string>(table_data[0 ].rows [0 ][1 ]) == " 30" && " Expected second column to be '30'" );
229- assert (std::get<std::string>(table_data[0 ].rows [0 ][2 ]) == " New York" && " Expected third column to be 'New York'" );
224+ const auto & table_pair = *table_data.begin ();
225+ const auto & table = table_pair.second ;
226+
227+ assert (table.rows .size () == 2 && " Expected 2 rows of data" );
228+ assert (std::get<std::string>(table.rows [0 ][0 ]) == " Alice" && " Expected first column to be 'Alice'" );
229+ assert (std::get<std::string>(table.rows [0 ][1 ]) == " 30" && " Expected second column to be '30'" );
230+ assert (std::get<std::string>(table.rows [0 ][2 ]) == " New York" && " Expected third column to be 'New York'" );
230231 std::cout << " test_generate_table_data_default_column_types passed\n " ;
232+
231233}
232234
233235int main () {
0 commit comments