LCOV - code coverage report
Current view: top level - unit_tests/test_basic_math - test_find_index.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 37 37 100.0 %
Date: 2024-04-25 02:23:43 Functions: 9 9 100.0 %

          Line data    Source code
       1             : /*
       2             :  * test_find_index.cpp
       3             :  *
       4             :  *  Created on: Oct 30, 2013
       5             :  * @author Andrey Belomutskiy, (c) 2012-2020
       6             :  */
       7             : 
       8             : #include "pch.h"
       9             : #include "efi_interpolation.h"
      10             : 
      11           9 : static void testIndex(const int expected, const float array[], int size, float value) {
      12           9 :         ASSERT_EQ(expected, findIndex(array, size, value));
      13           9 :         ASSERT_EQ(expected, findIndex2(array, size, value));
      14             : }
      15             : 
      16           4 : TEST(misc, testFindIndex) {
      17           1 :         printf("*************************************************** testFindIndex\r\n");
      18             : /*
      19             :         {
      20             :                 // in real life we only use powers of 2 for sizes
      21             :                 float array5[] = { 1, 2, 3, 4, 5 };
      22             :                 const int size5 = 5;
      23             :                 printf("To the right5\r\n");
      24             :                 testIndex(4, array5, size5, 10.0);
      25             : 
      26             :                 printf("Middle2\r\n");
      27             :                 testIndex(3, array5, size5, 4);
      28             : 
      29             :                 printf("Middle2\r\n");
      30             :                 testIndex(2, array5, size5, 3.1);
      31             : 
      32             :         }
      33             : */
      34             :         {
      35           1 :                 float array4[] = { 1, 2, 3, 4 };
      36           1 :                 const int size4 = 4;
      37             : 
      38           1 :                 printf("To the left\r\n");
      39           1 :                 testIndex(-1, array4, size4, -1.0);
      40             : 
      41           1 :                 printf("To the right4\r\n");
      42           1 :                 testIndex(3, array4, size4, 10.0);
      43             : 
      44           1 :                 printf("On the edge\r\n");
      45           1 :                 testIndex(3, array4, size4, 4.0);
      46             : 
      47           1 :                 printf("Another1\r\n");
      48           1 :                 testIndex(2, array4, size4, 3.9);
      49             : 
      50           1 :                 printf("Another2\r\n");
      51           1 :                 testIndex(3, array4, size4, 4.1);
      52             : 
      53           1 :                 printf("Another3\r\n");
      54           1 :                 testIndex(1, array4, size4, 2);
      55             : 
      56           1 :                 printf("Left edge1\r\n");
      57           1 :                 testIndex(0, array4, size4, 1);
      58             : 
      59           1 :                 printf("Left edge2\r\n");
      60           1 :                 testIndex(0, array4, size4, 1.1);
      61             : 
      62           1 :                 printf("Middle\r\n");
      63           1 :                 testIndex(2, array4, size4, 3);
      64             :         }
      65           1 : }
      66             : 
      67           4 : TEST(misc, testSetTableValue) {
      68           1 :         printf("*************************************************** testSetTableValue\r\n");
      69             : 
      70           1 :         persistent_config_s config;
      71             : 
      72          17 :         for (int i = 0; i < CLT_CURVE_SIZE; i++) {
      73          16 :                 config.cltFuelCorrBins[i] = -40 + i * 10;
      74          16 :                 config.cltFuelCorr[i] = 1;
      75             :         }
      76             : 
      77           1 :         ASSERT_EQ(1, config.cltFuelCorr[0]);
      78             : 
      79           1 :         setCurveValue(config.cltFuelCorrBins, config.cltFuelCorr, CLT_CURVE_SIZE, -40, 1.5);
      80           1 :         ASSERT_FLOAT_EQ(1.5, config.cltFuelCorr[0]);
      81             : 
      82           1 :         setCurveValue(config.cltFuelCorrBins, config.cltFuelCorr, CLT_CURVE_SIZE, -50, 1.4);
      83           1 :         ASSERT_FLOAT_EQ(1.4, config.cltFuelCorr[0]);
      84             : 
      85             : }

Generated by: LCOV version 1.14