Skip to content

Commit 9add8e1

Browse files
committed
resolve even more comments
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
1 parent 6d2c709 commit 9add8e1

File tree

1 file changed

+76
-56
lines changed

1 file changed

+76
-56
lines changed

tests/cpp_unit_tests/test_current_sensor.cpp

Lines changed: 76 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ TEST_CASE("Test current sensor") {
7272
CurrentSensorCalcParam<symmetric_t> sym_sensor_param = sym_current_sensor.calc_param<symmetric_t>();
7373
CurrentSensorCalcParam<asymmetric_t> asym_sensor_param = sym_current_sensor.calc_param<asymmetric_t>();
7474

75-
// These two are only to test the residuals for local angle measurements.
76-
// conj(i) simulates the phase shift for local angle output residuals when the reference voltage is
77-
// real.
7875
CurrentSensorOutput<symmetric_t> const sym_sensor_output =
7976
(angle_measurement_type == AngleMeasurementType::global_angle)
8077
? sym_current_sensor.get_output<symmetric_t>(i_sym, ComplexValue<symmetric_t>{1.0})
@@ -127,62 +124,86 @@ TEST_CASE("Test current sensor") {
127124
for (auto const terminal_type :
128125
{MeasuredTerminalType::source, MeasuredTerminalType::shunt, MeasuredTerminalType::load,
129126
MeasuredTerminalType::generator, MeasuredTerminalType::node}) {
130-
CHECK_THROWS_AS(
131-
(CurrentSensor<symmetric_t>{
132-
{1, 1, terminal_type, AngleMeasurementType::global_angle, 1.0, 1.0, 1.0, 1.0}, 1.0}),
133-
InvalidMeasuredTerminalType);
127+
for (auto const angle_measurement_type :
128+
{AngleMeasurementType::global_angle, AngleMeasurementType::local_angle}) {
129+
CAPTURE(terminal_type);
130+
CAPTURE(angle_measurement_type);
131+
132+
CHECK_THROWS_AS((CurrentSensor<symmetric_t>{
133+
{1, 1, terminal_type, angle_measurement_type, 1.0, 1.0, 1.0, 1.0}, 1.0}),
134+
InvalidMeasuredTerminalType);
135+
}
134136
}
135137
}
136138
SUBCASE("Symmetric calculation parameters") {
137139
double const u_rated = 10.0e3;
138140
double const base_current = base_power_3p / u_rated / sqrt3;
139-
140-
CurrentSensor<symmetric_t> sym_current_sensor{
141-
{.id = 1,
142-
.measured_object = 1,
143-
.measured_terminal_type = MeasuredTerminalType::branch3_1,
144-
.angle_measurement_type = AngleMeasurementType::global_angle},
145-
u_rated};
146-
147-
SUBCASE("No phase shift") {
148-
sym_current_sensor.update(
149-
{.id = 1, .i_sigma = 1.0, .i_angle_sigma = 0.2, .i_measured = 1.0, .i_angle_measured = 0.0});
150-
auto const sym_param = sym_current_sensor.calc_param<symmetric_t>();
151-
152-
CHECK(sym_param.angle_measurement_type == AngleMeasurementType::global_angle);
153-
CHECK(sym_param.measurement.real_component.variance == doctest::Approx(pow(1.0 / base_current, 2)));
154-
CHECK(sym_param.measurement.imag_component.variance == doctest::Approx(pow(0.2 / base_current, 2)));
155-
CHECK(real(sym_param.measurement.value()) == doctest::Approx(1.0 / base_current));
156-
CHECK(imag(sym_param.measurement.value()) == doctest::Approx(0.0 / base_current));
157-
}
158-
159-
SUBCASE("90deg phase shift") {
160-
sym_current_sensor.update(
161-
{.id = 1, .i_sigma = 1.0, .i_angle_sigma = 0.2, .i_measured = 1.0, .i_angle_measured = pi / 2});
162-
auto const sym_param = sym_current_sensor.calc_param<symmetric_t>();
163-
164-
CHECK(sym_param.angle_measurement_type == AngleMeasurementType::global_angle);
165-
CHECK(sym_param.measurement.real_component.variance == doctest::Approx(pow(0.2 / base_current, 2)));
166-
CHECK(sym_param.measurement.imag_component.variance == doctest::Approx(pow(1.0 / base_current, 2)));
167-
CHECK(real(sym_param.measurement.value()) == doctest::Approx(0.0 / base_current));
168-
CHECK(imag(sym_param.measurement.value()) == doctest::Approx(1.0 / base_current));
169-
}
170-
171-
SUBCASE("45deg phase shift") {
172-
using std::numbers::sqrt2;
173-
constexpr auto inv_sqrt2 = sqrt2 / 2;
174-
175-
sym_current_sensor.update(
176-
{.id = 1, .i_sigma = 1.0, .i_angle_sigma = 0.2, .i_measured = 1.0, .i_angle_measured = pi / 4});
177-
auto const sym_param = sym_current_sensor.calc_param<symmetric_t>();
178-
179-
CHECK(sym_param.angle_measurement_type == AngleMeasurementType::global_angle);
180-
CHECK(sym_param.measurement.real_component.variance ==
181-
doctest::Approx(1.04 / 2.0 / (base_current * base_current)));
182-
CHECK(sym_param.measurement.imag_component.variance ==
183-
doctest::Approx(sym_param.measurement.real_component.variance));
184-
CHECK(real(sym_param.measurement.value()) == doctest::Approx(inv_sqrt2 / base_current));
185-
CHECK(imag(sym_param.measurement.value()) == doctest::Approx(real(sym_param.measurement.value())));
141+
for (auto const terminal_type :
142+
{MeasuredTerminalType::branch_from, MeasuredTerminalType::branch_to, MeasuredTerminalType::branch3_1,
143+
MeasuredTerminalType::branch3_2, MeasuredTerminalType::branch3_3}) {
144+
for (auto const angle_measurement_type :
145+
{AngleMeasurementType::global_angle, AngleMeasurementType::local_angle}) {
146+
CurrentSensor<symmetric_t> sym_current_sensor{{.id = 1,
147+
.measured_object = 1,
148+
.measured_terminal_type = terminal_type,
149+
.angle_measurement_type = angle_measurement_type},
150+
u_rated};
151+
152+
SUBCASE("No phase shift") {
153+
sym_current_sensor.update({.id = 1,
154+
.i_sigma = 1.0,
155+
.i_angle_sigma = 0.2,
156+
.i_measured = 1.0,
157+
.i_angle_measured = 0.0});
158+
auto const sym_param = sym_current_sensor.calc_param<symmetric_t>();
159+
160+
CHECK(sym_param.angle_measurement_type == angle_measurement_type);
161+
CHECK(sym_param.measurement.real_component.variance ==
162+
doctest::Approx(pow(1.0 / base_current, 2)));
163+
CHECK(sym_param.measurement.imag_component.variance ==
164+
doctest::Approx(pow(0.2 / base_current, 2)));
165+
CHECK(real(sym_param.measurement.value()) == doctest::Approx(1.0 / base_current));
166+
CHECK(imag(sym_param.measurement.value()) == doctest::Approx(0.0 / base_current));
167+
}
168+
169+
SUBCASE("90deg phase shift") {
170+
sym_current_sensor.update({.id = 1,
171+
.i_sigma = 1.0,
172+
.i_angle_sigma = 0.2,
173+
.i_measured = 1.0,
174+
.i_angle_measured = pi / 2});
175+
auto const sym_param = sym_current_sensor.calc_param<symmetric_t>();
176+
177+
CHECK(sym_param.angle_measurement_type == angle_measurement_type);
178+
CHECK(sym_param.measurement.real_component.variance ==
179+
doctest::Approx(pow(0.2 / base_current, 2)));
180+
CHECK(sym_param.measurement.imag_component.variance ==
181+
doctest::Approx(pow(1.0 / base_current, 2)));
182+
CHECK(real(sym_param.measurement.value()) == doctest::Approx(0.0 / base_current));
183+
CHECK(imag(sym_param.measurement.value()) == doctest::Approx(1.0 / base_current));
184+
}
185+
186+
SUBCASE("45deg phase shift") {
187+
using std::numbers::sqrt2;
188+
constexpr auto inv_sqrt2 = sqrt2 / 2;
189+
190+
sym_current_sensor.update({.id = 1,
191+
.i_sigma = 1.0,
192+
.i_angle_sigma = 0.2,
193+
.i_measured = 1.0,
194+
.i_angle_measured = pi / 4});
195+
auto const sym_param = sym_current_sensor.calc_param<symmetric_t>();
196+
197+
CHECK(sym_param.angle_measurement_type == angle_measurement_type);
198+
CHECK(sym_param.measurement.real_component.variance ==
199+
doctest::Approx(1.04 / 2.0 / (base_current * base_current)));
200+
CHECK(sym_param.measurement.imag_component.variance ==
201+
doctest::Approx(sym_param.measurement.real_component.variance));
202+
CHECK(real(sym_param.measurement.value()) == doctest::Approx(inv_sqrt2 / base_current));
203+
CHECK(imag(sym_param.measurement.value()) ==
204+
doctest::Approx(real(sym_param.measurement.value())));
205+
}
206+
}
186207
}
187208
}
188209
}
@@ -260,7 +281,6 @@ TEST_CASE("Test current sensor") {
260281
constexpr auto i_sigma = 3.0;
261282
constexpr auto i_angle_sigma = 4.0;
262283
constexpr auto u_rated = 10.0e3;
263-
MeasuredTerminalType const measured_terminal_type = MeasuredTerminalType::branch_from;
264284

265285
CurrentSensorUpdate<asymmetric_t> cs_update{
266286
.id = 1, .i_sigma = nan, .i_angle_sigma = nan, .i_measured = r_nan, .i_angle_measured = r_nan};
@@ -319,7 +339,7 @@ TEST_CASE("Test current sensor") {
319339

320340
CurrentSensor<asymmetric_t> const current_sensor{{.id = 1,
321341
.measured_object = 1,
322-
.measured_terminal_type = measured_terminal_type,
342+
.measured_terminal_type = MeasuredTerminalType::branch_from,
323343
.angle_measurement_type = AngleMeasurementType::global_angle,
324344
.i_sigma = i_sigma,
325345
.i_angle_sigma = i_angle_sigma,

0 commit comments

Comments
 (0)