|
| static void | checkShiftedAverage (const int32_t amplitude, const int32_t offset, const int32_t noise, const int32_t delta) |
| |
| int | main (int argc, char **argv) |
| |
| static double | referenceVrms (uint32_t meanSquare, uint16_t factor, float cal) |
| | The float arithmetic being replaced, in hundredths of a volt (x4 for long periods).
|
| |
| static double | referenceWatts (int32_t averagePower, float cal) |
| | The float arithmetic being replaced, in watts (import = +ve).
|
| |
| void | setUp (void) |
| |
| void | tearDown (void) |
| |
| void | test_average_power_shifted_is_the_exact_average (void) |
| |
| void | test_average_power_unshifted_is_the_quotient (void) |
| |
| void | test_isqrt_at_every_boundary (void) |
| | Every rounding boundary of every root: round(sqrt(x)) changes from r to r + 1 between r^2 + r and r^2 + r + 1, since (r + 0.5)^2 = r^2 + r + 0.25.
|
| |
| void | test_isqrt_edge_cases (void) |
| |
| void | test_isqrt_matches_the_reference (void) |
| | 2 million values over the whole 32-bit range, against sqrt() in double precision (exact here).
|
| |
| void | test_isqrt_of_the_largest_value_saturates (void) |
| |
| void | test_power_calibration_is_constexpr (void) |
| |
| void | test_power_shift_follows_the_sample_count (void) |
| |
| void | test_power_shift_keeps_30_s_of_any_signal_in_32_bits (void) |
| |
| void | test_shifted_sum_is_within_half_the_shift_over_30_s (void) |
| |
| void | test_shifted_sum_keeps_the_average_of_a_noisy_signal_over_30_s (void) |
| |
| void | test_sqrtScaled_keeps_15_significant_bits (void) |
| |
| void | test_sqrtScaled_of_zero (void) |
| |
| void | test_valid_voltage_calibration (void) |
| |
| void | test_voltage_calibration_is_constexpr (void) |
| |
| void | test_vrms_at_230_V (void) |
| |
| void | test_vrms_factor_follows_the_scaling_of_the_isr (void) |
| |
| void | test_vrms_matches_the_reference_long_period (void) |
| |
| void | test_vrms_matches_the_reference_short_period (void) |
| |
| void | test_vrms_of_zero (void) |
| |
| void | test_vrms_saturates (void) |
| |
| void | test_watts_differs_from_the_float_code_by_at_most_1_W (void) |
| |
| void | test_watts_is_sign_symmetric (void) |
| |
| void | test_watts_matches_the_reference_extremes (void) |
| |
| void | test_watts_matches_the_reference_new_board (void) |
| |
| void | test_watts_matches_the_reference_old_board (void) |
| |
| void | test_watts_saturates_beyond_int16 (void) |
| |
| template<uint8_t N> |
| static double | worstVrmsError (uint16_t factor, const float(&cal)[N], uint32_t maxMeanSquare) |
| | Largest error of vrms() against the reference, from 0 to the largest ADC voltage, beyond what the 16-bit square root and calibration constant explain.
|
| |
| template<uint8_t N> |
| static double | worstWattsError (const float(&cal)[N]) |
| | Largest error of watts() against the reference, over the full input range, beyond what the 16-bit calibration constant explains.
|
| |
|
| static constexpr int32_t | FULL_SCALE { 1L << 18 } |
| |
| static constexpr float | largeCal [] { 0.5F, 0.5F, 0.5F } |
| |
| static constexpr float | newBoard20Cal [] { 0.057281F, 0.057281F, 0.057281F } |
| |
| static constexpr float | newBoard50Cal [] { 0.1432025F, 0.1432025F, 0.1432025F } |
| |
| static constexpr float | newBoardVCal [] { 0.888065256F, 0.888065256F, 0.888065256F } |
| |
| static constexpr float | oldBoardCal [] { 0.05F, 0.05F, 0.05F } |
| |
| static constexpr float | oldBoardVCal [] { 0.8151F, 0.8184F, 0.8195F } |
| |
| static constexpr float | smallCal [] { 0.02F, 0.02F, 0.02F } |
| |
Native unit tests for datalog_math.h.
The integer datalog arithmetic must reproduce the float arithmetic it replaces (#120), power_L = -(sumP / n) * f_powerCal[phase] Vrms_L_x100 = factor * f_voltageCal[phase] * sqrt(sum_Vsquared / n) over the full input range, without overflow. The float expressions, evaluated in double precision, are the reference. No config.h, no stubs.
Definition in file test_main.cpp.
| static void checkShiftedAverage |
( |
const int32_t | amplitude, |
|
|
const int32_t | offset, |
|
|
const int32_t | noise, |
|
|
const int32_t | delta ) |
|
static |
30 s at 50 Hz, 32 sample sets per cycle, summed as the ISR does (rounded, / 16), against the exact average (64-bit sum, here only); noise: pseudo-random, uniform over +-noise
Definition at line 288 of file test_main.cpp.
template<uint8_t N>
| static double worstVrmsError |
( |
uint16_t | factor, |
|
|
const float(&) | cal[N], |
|
|
uint32_t | maxMeanSquare ) |
|
static |
Largest error of vrms() against the reference, from 0 to the largest ADC voltage, beyond what the 16-bit square root and calibration constant explain.
Both have at least 16 significant bits (relative error <= 2^-16 each, 2^-14 with a margin), and the result is rounded (<= 0.5): the returned value must stay <= 0.5, i.e. 0.012 V at most at 230 V.
Definition at line 89 of file test_main.cpp.
template<uint8_t N>
| static double worstWattsError |
( |
const float(&) | cal[N] | ) |
|
|
static |
Largest error of watts() against the reference, over the full input range, beyond what the 16-bit calibration constant explains.
The calibration constant has at least 16 significant bits (relative error <= 2^-16, the same constant as in the ISR), and the result is rounded (<= 0.5 W): the returned value must stay <= 0.5 W.
Definition at line 60 of file test_main.cpp.