3-phase PV router
Loading...
Searching...
No Matches
test_main.cpp File Reference

Native unit tests for energy_bucket.h. More...

#include <unity.h>
#include <math.h>
#include "energy_bucket.h"
Include dependency graph for test_main.cpp:

Go to the source code of this file.

Functions

static void checkAgainstReference (const float(&cal)[3])
 Every average power from -FULL_SCALE to +FULL_SCALE, in uneven steps.
 
template<uint8_t SUPPLY_FREQUENCY>
void checkHundredthsOfJoule ()
 
static double exactReference (int32_t sumP, uint8_t n, float cal)
 The exact energy of one cycle: no truncating division, in bucket units.
 
static int32_t generalRounding (int32_t power, uint16_t calFixed, uint8_t shift)
 contribution() with the general rounding, (product + 2^(r-1)) >> r, in 64 bits.
 
int main (int, char **)
 
static double quantisationError (float cal, uint8_t shift)
 Relative error of a quantised calibration value.
 
static double reference (int32_t averagePower, float cal)
 The float arithmetic being replaced, in bucket units.
 
void setUp (void)
 
void tearDown (void)
 
void test_bucket_capacity_fits_in_32_bits (void)
 
void test_contribution_at_full_scale_does_not_overflow (void)
 
void test_contribution_is_sign_symmetric (void)
 
void test_contribution_matches_the_reference_for_a_typical_calibration (void)
 
void test_contribution_matches_the_reference_for_extreme_calibrations (void)
 
void test_contribution_of_zero_is_zero (void)
 
void test_contribution_rounding_shortcut_is_exact (void)
 
void test_fromWatts_scales_by_the_fraction_bits (void)
 
void test_hundredths_of_joule_at_50Hz (void)
 
void test_hundredths_of_joule_at_60Hz (void)
 
void test_largest_value_fills_16_bits (void)
 
void test_no_drift_over_one_minute (void)
 
void test_per_sample_agrees_with_the_division_path (void)
 
void test_per_sample_contribution_matches_the_exact_reference (void)
 
void test_per_sample_fallback_for_an_unexpected_cycle_length (void)
 
void test_per_sample_full_scale_does_not_overflow (void)
 
void test_per_sample_largest_value_fills_16_bits (void)
 
void test_per_sample_no_drift_over_one_minute (void)
 
void test_per_sample_shift_and_values (void)
 
void test_per_sample_shift_for_60Hz (void)
 
void test_quantisation_error_is_negligible (void)
 
void test_shift_follows_the_largest_value (void)
 
void test_shift_for_a_typical_calibration (void)
 
void test_shift_for_large_and_small_values (void)
 
void test_toFixed_rounds_to_nearest (void)
 
void test_typical_set_quantisation_error (void)
 
void test_valid_calibration_accepts_realistic_values (void)
 
void test_valid_calibration_rejects_zero_negative_and_huge_values (void)
 

Variables

static constexpr int32_t FULL_SCALE { 1L << 18 }
 
static constexpr float largeCal [] { 0.1F, 0.1F, 0.1F }
 
static constexpr uint8_t N_MAX_50HZ { 36 }
 
static constexpr uint8_t N_MIN_50HZ { 28 }
 
static constexpr float smallCal [] { 0.02F, 0.02F, 0.02F }
 
static constexpr float typicalCal [] { 0.042346F, 0.043453F, 0.042969F }
 

Detailed Description

Native unit tests for energy_bucket.h.

The integer energy bucket must reproduce the float arithmetic it replaces, bucket += (l_sumP / n) * f_powerCal[phase] over the full input range, without overflow and without drifting over time. The float/double expression is the reference. No config.h, no stubs.

Definition in file test_main.cpp.

Function Documentation

◆ checkAgainstReference()

static void checkAgainstReference ( const float(&) cal[3])
static

Every average power from -FULL_SCALE to +FULL_SCALE, in uneven steps.

Definition at line 133 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkHundredthsOfJoule()

template<uint8_t SUPPLY_FREQUENCY>
void checkHundredthsOfJoule ( )

Definition at line 426 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exactReference()

static double exactReference ( int32_t sumP,
uint8_t n,
float cal )
static

The exact energy of one cycle: no truncating division, in bucket units.

Definition at line 271 of file test_main.cpp.

Here is the caller graph for this function:

◆ generalRounding()

static int32_t generalRounding ( int32_t power,
uint16_t calFixed,
uint8_t shift )
static

contribution() with the general rounding, (product + 2^(r-1)) >> r, in 64 bits.

Definition at line 181 of file test_main.cpp.

Here is the caller graph for this function:

◆ main()

int main ( int ,
char **  )

Definition at line 461 of file test_main.cpp.

Here is the call graph for this function:

◆ quantisationError()

static double quantisationError ( float cal,
uint8_t shift )
static

Relative error of a quantised calibration value.

Definition at line 34 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reference()

static double reference ( int32_t averagePower,
float cal )
static

The float arithmetic being replaced, in bucket units.

Definition at line 28 of file test_main.cpp.

Here is the caller graph for this function:

◆ setUp()

void setUp ( void )

Definition at line 18 of file test_main.cpp.

◆ tearDown()

void tearDown ( void )

Definition at line 19 of file test_main.cpp.

◆ test_bucket_capacity_fits_in_32_bits()

void test_bucket_capacity_fits_in_32_bits ( void )

Definition at line 416 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_contribution_at_full_scale_does_not_overflow()

void test_contribution_at_full_scale_does_not_overflow ( void )

Definition at line 170 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_contribution_is_sign_symmetric()

void test_contribution_is_sign_symmetric ( void )

Definition at line 231 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_contribution_matches_the_reference_for_a_typical_calibration()

void test_contribution_matches_the_reference_for_a_typical_calibration ( void )

Definition at line 152 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_contribution_matches_the_reference_for_extreme_calibrations()

void test_contribution_matches_the_reference_for_extreme_calibrations ( void )

Definition at line 157 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_contribution_of_zero_is_zero()

void test_contribution_of_zero_is_zero ( void )

Definition at line 163 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_contribution_rounding_shortcut_is_exact()

void test_contribution_rounding_shortcut_is_exact ( void )

Definition at line 191 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_fromWatts_scales_by_the_fraction_bits()

void test_fromWatts_scales_by_the_fraction_bits ( void )

Definition at line 408 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_hundredths_of_joule_at_50Hz()

void test_hundredths_of_joule_at_50Hz ( void )

Definition at line 441 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_hundredths_of_joule_at_60Hz()

void test_hundredths_of_joule_at_60Hz ( void )

Definition at line 451 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_largest_value_fills_16_bits()

void test_largest_value_fills_16_bits ( void )

Definition at line 70 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_no_drift_over_one_minute()

void test_no_drift_over_one_minute ( void )

Definition at line 243 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_per_sample_agrees_with_the_division_path()

void test_per_sample_agrees_with_the_division_path ( void )

Definition at line 326 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_per_sample_contribution_matches_the_exact_reference()

void test_per_sample_contribution_matches_the_exact_reference ( void )

Definition at line 304 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_per_sample_fallback_for_an_unexpected_cycle_length()

void test_per_sample_fallback_for_an_unexpected_cycle_length ( void )

Definition at line 347 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_per_sample_full_scale_does_not_overflow()

void test_per_sample_full_scale_does_not_overflow ( void )

Definition at line 370 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_per_sample_largest_value_fills_16_bits()

void test_per_sample_largest_value_fills_16_bits ( void )

Definition at line 295 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_per_sample_no_drift_over_one_minute()

void test_per_sample_no_drift_over_one_minute ( void )

Definition at line 384 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_per_sample_shift_and_values()

void test_per_sample_shift_and_values ( void )

Definition at line 276 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_per_sample_shift_for_60Hz()

void test_per_sample_shift_for_60Hz ( void )

Definition at line 287 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_quantisation_error_is_negligible()

void test_quantisation_error_is_negligible ( void )

Definition at line 87 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_shift_follows_the_largest_value()

void test_shift_follows_the_largest_value ( void )

Definition at line 62 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_shift_for_a_typical_calibration()

void test_shift_for_a_typical_calibration ( void )

Definition at line 49 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_shift_for_large_and_small_values()

void test_shift_for_large_and_small_values ( void )

Definition at line 56 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_toFixed_rounds_to_nearest()

void test_toFixed_rounds_to_nearest ( void )

Definition at line 79 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_typical_set_quantisation_error()

void test_typical_set_quantisation_error ( void )

Definition at line 98 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_valid_calibration_accepts_realistic_values()

void test_valid_calibration_accepts_realistic_values ( void )

Definition at line 108 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_valid_calibration_rejects_zero_negative_and_huge_values()

void test_valid_calibration_rejects_zero_negative_and_huge_values ( void )

Definition at line 117 of file test_main.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ FULL_SCALE

int32_t FULL_SCALE { 1L << 18 }
staticconstexpr

Definition at line 25 of file test_main.cpp.

◆ largeCal

float largeCal[] { 0.1F, 0.1F, 0.1F }
staticconstexpr

Definition at line 42 of file test_main.cpp.

◆ N_MAX_50HZ

uint8_t N_MAX_50HZ { 36 }
staticconstexpr

Definition at line 268 of file test_main.cpp.

◆ N_MIN_50HZ

uint8_t N_MIN_50HZ { 28 }
staticconstexpr

Definition at line 267 of file test_main.cpp.

◆ smallCal

float smallCal[] { 0.02F, 0.02F, 0.02F }
staticconstexpr

Definition at line 43 of file test_main.cpp.

◆ typicalCal

float typicalCal[] { 0.042346F, 0.043453F, 0.042969F }
staticconstexpr

Definition at line 41 of file test_main.cpp.