LCOV - code coverage report
Current view: top level - unit_tests/tests/util - test_error_accumulator.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 24 24 100.0 %
Date: 2024-04-25 02:23:43 Functions: 16 16 100.0 %

          Line data    Source code
       1             : #include "pch.h"
       2             : 
       3             : #include "error_accumulator.h"
       4             : 
       5           4 : TEST(errorAccumulator, ignoreSmallError) {
       6           1 :         ErrorAccumulator dut;
       7           1 :         dut.init(5, 0.01);
       8             : 
       9     1000001 :         for (size_t i = 0; i < 1'000'000; i++) {
      10             :                 // An error just below the threshold should never trip
      11     1000000 :                 ASSERT_EQ(0, dut.accumulate(4));
      12             :         }
      13             : }
      14             : 
      15           4 : TEST(errorAccumulator, integrateError) {
      16           1 :         ErrorAccumulator dut;
      17           1 :         dut.init(5, 0.01);
      18             : 
      19         101 :         for (size_t i = 0; i < 100; i++) {
      20             :                 // error of 1 over the ignore value
      21         100 :                 dut.accumulate(6);
      22             :         }
      23             : 
      24             :         // Integral should be 1 * dt * 100 = 1.0
      25           1 :         ASSERT_NEAR(dut.getAccumulator(), 1, 0.001f);
      26             : }
      27             : 
      28           4 : TEST(errorAccumulator, integrateNegativeError) {
      29           1 :         ErrorAccumulator dut;
      30           1 :         dut.init(5, 0.01);
      31             : 
      32         101 :         for (size_t i = 0; i < 100; i++) {
      33             :                 // error of 1 over the ignore value, but negative
      34         100 :                 dut.accumulate(-6);
      35             :         }
      36             : 
      37             :         // Integral should be 1 * dt * 100 = 1.0
      38           1 :         ASSERT_NEAR(dut.getAccumulator(), 1, 0.001f);
      39             : }
      40             : 
      41           4 : TEST(errorAccumulator, integrateErrorBothSigns) {
      42           1 :         ErrorAccumulator dut;
      43           1 :         dut.init(5, 0.01);
      44             : 
      45         101 :         for (size_t i = 0; i < 100; i++) {
      46             :                 // These should collectively integrate 1 * dt worth of error
      47         100 :                 dut.accumulate(-5.5);
      48         100 :                 dut.accumulate(5.5);
      49             :         }
      50             : 
      51             :         // Integral should be 2 * 0.5 * dt * 100 = 1.0
      52           1 :         ASSERT_NEAR(dut.getAccumulator(), 1, 0.001f);
      53             : }

Generated by: LCOV version 1.14