@@ -815,7 +815,7 @@ TEST_CASE("Test statistics") {
815
815
}
816
816
}
817
817
818
- TEST_CASE (" Test statistics - accumulate " ) {
818
+ TEST_CASE (" Test statistics - combine " ) {
819
819
using statistics::combine;
820
820
using std::views::take;
821
821
@@ -1129,6 +1129,81 @@ TEST_CASE("Test statistics - accumulate") {
1129
1129
}
1130
1130
}
1131
1131
1132
+ TEST_CASE (" Test statistics - combine_magnitude" ) {
1133
+ using statistics::combine_magnitude;
1134
+ using std::views::take;
1135
+
1136
+ SUBCASE (" UniformComplexRandVar<symmetric_t>" ) {
1137
+ // using a template lambda to avoid code duplication and to avoid having to create a separate test case
1138
+ std::vector<UniformComplexRandVar<symmetric_t >> const measurements{
1139
+ {.value = ComplexValue<symmetric_t >{1.0 , 5.0 }, .variance = 0.2 },
1140
+ {.value = ComplexValue<symmetric_t >{2.0 , nan}, .variance = 0.3 },
1141
+ {.value = ComplexValue<symmetric_t >{4.0 , nan}, .variance = 0.6 }};
1142
+
1143
+ CHECK (combine_magnitude (measurements | take (0 )).value .real () == 0.0 );
1144
+ CHECK (is_nan (combine_magnitude (measurements | take (0 )).value .imag ()));
1145
+ CHECK (is_inf (combine_magnitude (measurements | take (0 )).variance ));
1146
+
1147
+ CHECK (combine_magnitude (measurements | take (1 )).value .real () == cabs (measurements.front ().value ));
1148
+ CHECK (is_nan (combine_magnitude (measurements | take (1 )).value .imag ()));
1149
+ CHECK (combine_magnitude (measurements | take (1 )).variance == measurements.front ().variance );
1150
+
1151
+ CHECK (combine_magnitude (measurements | take (2 )).value .real () ==
1152
+ doctest::Approx ((3.0 * std::sqrt (26.0 ) + 4.0 ) / 5.0 ));
1153
+ CHECK (is_nan (combine_magnitude (measurements | take (2 )).value .imag ()));
1154
+ CHECK (combine_magnitude (measurements | take (2 )).variance == doctest::Approx (3.0 / 25.0 ));
1155
+
1156
+ CHECK (combine_magnitude (measurements | take (3 )).value .real () ==
1157
+ doctest::Approx ((3.0 * std::sqrt (26.0 ) + 5.0 ) / 6.0 ));
1158
+ CHECK (is_nan (combine_magnitude (measurements | take (3 )).value .imag ()));
1159
+ CHECK (combine_magnitude (measurements | take (3 )).variance == doctest::Approx (1.0 / 10.0 ));
1160
+ }
1161
+
1162
+ SUBCASE (" UniformComplexRandVar<asymmetric_t>" ) {
1163
+ std::vector<UniformComplexRandVar<asymmetric_t >> const measurements{
1164
+ {.value = {RealValue<asymmetric_t >{1.0 , 2.0 , -1.0 }, RealValue<asymmetric_t >{5.0 , nan, 7.0 }},
1165
+ .variance = 0.2 },
1166
+ {.value = {RealValue<asymmetric_t >{2.0 , 4.0 , 3.0 }, RealValue<asymmetric_t >{nan}}, .variance = 0.3 },
1167
+ {.value = {RealValue<asymmetric_t >{4.0 , 5.0 , 6.0 }, RealValue<asymmetric_t >{nan}}, .variance = 0.6 }};
1168
+
1169
+ CHECK (combine_magnitude (measurements | take (0 )).value (0 ).real () == 0.0 );
1170
+ CHECK (combine_magnitude (measurements | take (0 )).value (1 ).real () == 0.0 );
1171
+ CHECK (combine_magnitude (measurements | take (0 )).value (2 ).real () == 0.0 );
1172
+ CHECK (is_nan (combine_magnitude (measurements | take (0 )).value (0 ).imag ()));
1173
+ CHECK (is_nan (combine_magnitude (measurements | take (0 )).value (0 ).imag ()));
1174
+ CHECK (is_nan (combine_magnitude (measurements | take (0 )).value (0 ).imag ()));
1175
+ CHECK (is_inf (combine_magnitude (measurements | take (0 )).variance ));
1176
+
1177
+ CHECK (combine_magnitude (measurements | take (1 )).value (0 ).real () == cabs (measurements.front ().value (0 )));
1178
+ CHECK (combine_magnitude (measurements | take (1 )).value (1 ).real () == cabs (measurements.front ().value (1 )));
1179
+ CHECK (combine_magnitude (measurements | take (1 )).value (2 ).real () == cabs (measurements.front ().value (2 )));
1180
+ CHECK (is_nan (combine_magnitude (measurements | take (1 )).value (0 ).imag ()));
1181
+ CHECK (is_nan (combine_magnitude (measurements | take (1 )).value (1 ).imag ()));
1182
+ CHECK (is_nan (combine_magnitude (measurements | take (1 )).value (2 ).imag ()));
1183
+ CHECK (combine_magnitude (measurements | take (1 )).variance == measurements.front ().variance );
1184
+
1185
+ CHECK (combine_magnitude (measurements | take (2 )).value (0 ).real () ==
1186
+ doctest::Approx ((3.0 * std::sqrt (26.0 ) + 4.0 ) / 5.0 ));
1187
+ CHECK (combine_magnitude (measurements | take (2 )).value (1 ).real () == doctest::Approx (14.0 / 5.0 ));
1188
+ CHECK (combine_magnitude (measurements | take (2 )).value (2 ).real () ==
1189
+ doctest::Approx ((6.0 + 15.0 * std::sqrt (2.0 )) / 5.0 ));
1190
+ CHECK (is_nan (combine_magnitude (measurements | take (2 )).value (0 ).imag ()));
1191
+ CHECK (is_nan (combine_magnitude (measurements | take (2 )).value (1 ).imag ()));
1192
+ CHECK (is_nan (combine_magnitude (measurements | take (2 )).value (2 ).imag ()));
1193
+ CHECK (combine_magnitude (measurements | take (2 )).variance == doctest::Approx (3.0 / 25.0 ));
1194
+
1195
+ CHECK (combine_magnitude (measurements | take (3 )).value (0 ).real () ==
1196
+ doctest::Approx ((3.0 * std::sqrt (26.0 ) + 5.0 ) / 6.0 ));
1197
+ CHECK (combine_magnitude (measurements | take (3 )).value (1 ).real () == doctest::Approx (19.0 / 6.0 ));
1198
+ CHECK (combine_magnitude (measurements | take (3 )).value (2 ).real () ==
1199
+ doctest::Approx ((4.0 + 5.0 * std::sqrt (2.0 )) / 2.0 ));
1200
+ CHECK (is_nan (combine_magnitude (measurements | take (3 )).value (0 ).imag ()));
1201
+ CHECK (is_nan (combine_magnitude (measurements | take (3 )).value (1 ).imag ()));
1202
+ CHECK (is_nan (combine_magnitude (measurements | take (3 )).value (2 ).imag ()));
1203
+ CHECK (combine_magnitude (measurements | take (3 )).variance == doctest::Approx (1.0 / 10.0 ));
1204
+ }
1205
+ }
1206
+
1132
1207
TEST_SUITE_END ();
1133
1208
1134
1209
} // namespace power_grid_model
0 commit comments