@@ -108,27 +108,32 @@ TEST_CASE("Basic CSVReader Iterator Test", "[read_ints_iter]") {
108108
109109// ! [CSVReader Iterator 2]
110110TEST_CASE (" CSVReader Iterator + std::max_elem" , " [iter_max_elem]" ) {
111- // The first is such that each value in the ith row is the number i
112- // There are 100 rows
113- // The second file is a database of California state employee salaries
114- CSVReader r1 (" ./tests/data/fake_data/ints.csv" ),
115- r2 (" ./tests/data/real_data/2015_StateDepartment.csv" );
116-
117- // Find largest number
118- auto int_finder = [](CSVRow& left, CSVRow& right) {
119- return (left[" A" ].get <int >() < right[" A" ].get <int >());
120- };
111+ SECTION (" Find Max Element with std::max_element" ) {
112+ // The first is such that each value in the ith row is the number i
113+ // There are 100 rows
114+ CSVReader r1 (" ./tests/data/fake_data/ints.csv" );
115+
116+ // Find largest number
117+ auto int_finder = [](CSVRow& left, CSVRow& right) {
118+ return (left[" A" ].get <int >() < right[" A" ].get <int >());
119+ };
120+
121+ auto max_int = std::max_element (r1.begin (), r1.end (), int_finder);
122+ REQUIRE ((*max_int)[" A" ] == 100 );
123+ }
121124
122- auto max_int = std::max_element (r1.begin (), r2.end (), int_finder);
125+ SECTION (" Find Max Element with std::max_element - Large File" ) {
126+ // The second file is a database of California state employee salaries
127+ CSVReader r2 (" ./tests/data/real_data/2015_StateDepartment.csv" );
128+
129+ // Find highest salary
130+ auto wage_finder = [](CSVRow& left, CSVRow& right) {
131+ return (left[" Total Wages" ].get <double >() < right[" Total Wages" ].get <double >());
132+ };
123133
124- // Find highest salary
125- auto wage_finder = [](CSVRow& left, CSVRow& right) {
126- return (left[" Total Wages" ].get <double >() < right[" Total Wages" ].get <double >());
127- };
134+ auto max_wage = std::max_element (r2.begin (), r2.end (), wage_finder);
128135
129- auto max_wage = std::max_element (r2.begin (), r2.end (), wage_finder);
130-
131- REQUIRE ((*max_int)[" A" ] == 100 );
132- REQUIRE ((*max_wage)[" Total Wages" ] == " 812064.87" );
136+ REQUIRE ((*max_wage)[" Total Wages" ] == " 812064.87" );
137+ }
133138}
134139// ! [CSVReader Iterator 2]
0 commit comments