LCOV - code coverage report
Current view: top level - unit_tests/tests - test_hip9011.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 41 41 100.0 %
Date: 2024-04-22 23:59:02 Functions: 19 19 100.0 %

          Line data    Source code
       1             : /*
       2             :  * @file test_hip9011.cpp
       3             :  *
       4             :  *  Created on: Mar 22, 2018
       5             :  */
       6             : 
       7             : #include "pch.h"
       8             : #include "hip9011_logic.h"
       9             : 
      10             : using ::testing::_;
      11             : 
      12           4 : TEST(hip9011, lookup) {
      13           1 :         HIP9011 instance(NULL);
      14             : 
      15           1 :         assertEqualsM2("", 3183.1013, instance.getRpmByAngleWindowAndTimeUs(600, 360), 0.1);
      16           1 :         assertEqualsM2("40us", 47746.5195, instance.getRpmByAngleWindowAndTimeUs(40, 360), 0.1);
      17             : 
      18           1 :         assertEqualsM2("600us 50 degree", 442.0974, instance.getRpmByAngleWindowAndTimeUs(600, 50), 0.1);
      19           1 :         assertEqualsM2("240us 50 degree", 1105.2435, instance.getRpmByAngleWindowAndTimeUs(240, 50), 0.1);
      20           1 :         assertEqualsM2("240us 50 degree", 6631.4619, instance.getRpmByAngleWindowAndTimeUs(40, 50), 0.1);
      21             : 
      22           1 :         EXPECT_EQ(0, instance.getGainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/3, 0, NAN, NAN));
      23           1 :         EXPECT_EQ(0, instance.getGainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/2, 0, NAN, NAN));
      24           1 :         EXPECT_EQ(47, instance.getGainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/0.234, 0, NAN, NAN));
      25           1 :         EXPECT_EQ(63, instance.getGainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/0.000001, 0, NAN, NAN));
      26           1 :         EXPECT_EQ(63, instance.getGainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/-1.0, 0, NAN, NAN));
      27             : 
      28           1 : }
      29             : 
      30           4 : TEST(hip9011, rpmLookup) {
      31           1 :         HIP9011 instance(NULL);
      32             : 
      33           1 :         instance.angleWindowWidth = 50.0;
      34           1 :         instance.prepareRpmLookup();
      35             : 
      36           1 :         EXPECT_EQ(31, instance.getIntegrationIndexByRpm(1));
      37           1 :         EXPECT_EQ(21, instance.getIntegrationIndexByRpm(1100));
      38           1 :         EXPECT_EQ(1, instance.getIntegrationIndexByRpm(6600));
      39           1 :         EXPECT_EQ(0, instance.getIntegrationIndexByRpm(16600));
      40           1 : }
      41             : 
      42           4 : TEST(hip9011, band) {
      43           1 :         HIP9011 instance(NULL);
      44             : 
      45           1 :         EXPECT_FLOAT_EQ(3, instance.getBand(/* knockBandCustom*/3, /*cylinderBore*/76, /*hip9011Gain*/NAN, 0, NAN, NAN));
      46           1 :         EXPECT_NEAR_M4(7.5389242, instance.getBand(/* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/NAN, 0, NAN, NAN));
      47             : 
      48           1 :         EXPECT_EQ(42, instance.getBandIndex(/* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/NAN, 0, NAN, NAN));
      49             : 
      50           1 : }
      51             : 
      52             : class MockHip9011Hardware : public Hip9011HardwareInterface
      53             : {
      54             : public:
      55           1 :         MockHip9011Hardware() {  }
      56             : 
      57           9 :     MOCK_METHOD2(sendSyncCommand, int(unsigned char, unsigned char *));
      58             : };
      59             : 
      60           4 : TEST(hip9011, configurationCommands) {
      61             : 
      62           1 :         MockHip9011Hardware mock;
      63             : 
      64           1 :         HIP9011 instance(&mock);
      65             : 
      66             : // want to invoke method with same parameters a few times
      67             : #define PARAMETERS 600, /* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/1, HIP_8MHZ_PRESCALER, 0.0, 50.0
      68             : 
      69             :          // Not making assumptions on the message send ...
      70           1 :         EXPECT_CALL(mock, sendSyncCommand(SET_GAIN_CMD(0xE), 0)).Times(1);
      71           1 :         EXPECT_CALL(mock, sendSyncCommand(SET_INTEGRATOR_CMD(0x1C), 0)).Times(1);
      72           1 :         EXPECT_CALL(mock, sendSyncCommand(SET_BAND_PASS_CMD(0x2A), 0)).Times(1);
      73           1 :         EXPECT_CALL(mock, sendSyncCommand(SET_PRESCALER_CMD(6), 0)).Times(1);
      74           1 :         instance.handleSettings(PARAMETERS);
      75             : 
      76             :         // initialization is over, no commands should be sent
      77           1 :         EXPECT_CALL(mock, sendSyncCommand(_, _)).Times(0);
      78           1 :         instance.handleSettings(PARAMETERS);
      79           2 : }

Generated by: LCOV version 1.14